struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: Struts - latest build
Date Wed, 21 Jun 2000 05:28:45 GMT
Kevin Duffey wrote:

> Hi,
> Sorry..posted this to the wrong subject in the group...trying again. If your
> reading this twice..I apologize for the mixup.
> I just downloaded the latest Struts. Damned if Craig implemented my
> suggestion! The ActionForward class for a return type from perform(). The
> only downside is..all my actions now have to be edited to return this type.
> Other than that..pretty kewl.
> So question to Craig...first, does each of my actions need to create a new
> ActionForward object, and populate it, then return that to use the
> forwarding capability that I assume is worked into ActionServlet (is it?).

If you use the new capabilities of the action.xml method (the <forward>
element), you can set up a set of logical mappings that you can just look up,
instead of having to create one every time.  See the usage in the example
application -- for example, LogonAction does this when it sees a successful user

    return (mapping.findForward("success"));

which returns the configured mapping for the logical name "forward" that was set
up at initialization time.

> A thought..return an Object type, instead of ActionForward. In
> ActionServlet, use instanceof to see if it is of type String. If it
> is..forward to that page. If not, check if it is of type ActionForward..and
> if so..typecast it and use that object. The reason I ask for this is..its
> often nice to just return a String of the page to forward to, instead of
> having to create a new object then return that. While returning a string
> creates a new object, its a bit less code for every action to just return
> the String.

The reason it returns ActionForward instead of String is -- at the suggestion of
someone else on the list -- sometimes you want to forward and sometimes you want
to redirect.  The ActionForward object lets you specify both the destination URL
and the redirect flag.

In ActionServlet, the current implementation looks like this:

    ActionForward forward =
        actionInstance.perform(this, mapping, formInstance,
            request, response);
    if (forward != null) {
        String path = forward.getPath();
        if (forward.getRedirect())
        else {
            RequestDispatcher rd =
            rd.forward(request, response);

so if you want to redirect instead of forward, set your <forward> entry up like

    <forward name="success" path="logon.jsp" redirect="true"/>

and that will happen for you (this also answers your second email question about
whether Struts can redirect instead of forward).

> Ofcourse..I would much rather use a "mapping" in the action.xml file, which
> I see you added as that I can just have a lookup done based on the
> action being called. But I am not quite sure how that works. Do I still need
> to create an ActionForward object, populate only the "forward" name, and the
> ActionServlet checks to see if the relative path is empty..if so, do a
> lookup on the name from the action, or what?

See the example application, and the discussion above.

> A feature request:
>   Ability to NOT use the international classes, via an init param. In other
> words, conditionalize the use of a resource bundle, getMessage() calls, etc.
> That way..if my app is strictly US bound, I don't have to worry about the
> JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
> code under JDK 1.3. I found out that Orion works fine with Struts, except
> when running Orion under JDK 1.3, because there is a bug in JDK 1.3
> assocated with the getResourceBundle() call or something. Is this true?

I will look at the implications of this.

> Thanks.


View raw message