You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kevin Duffey <kd...@buymedia.com> on 2000/06/25 00:13:49 UTC

Struts forwardin/redirect idea

Hi,

Instead of having to specify in every <forward..> tag, can you add
functionality that uses a "default" init parameter as the "default" flag to
foward or redirect. By this I mean, allow an init parameter in web.xml that
specifies if ALL forwarding should be done via redirects, or forwarding via
RequestDispatcher. This way, I can change the functionality of ALL redirects
in one place..if need be. To add to this, IF (and only if) the redirect=".."
exists in the <forward tag>, does it OVERRIDE the "init" value. I find it
cumbersome (ok..Im being lazy) to keep typing in "false" for every action.
But, there is a special case when I would want to use redirects for
everything, instead of forwarding. For example, our live site uses IIS/JRUN,
where as I am using Orion to develop the framework on. JRUN supports Servlet
2.1, and other than taglibs, I believe the framework will work with Servlet
2.1 for forwarding and redirects. The only thing I can see not working is
the taglibs.

Anyways..I'd like to hear if others would like this feature too...I think it
would be great. Or..does it already exist? Should be only a few lines of
code and it wouldn't break the source at all..just add a feature.

Thanks.


Re: Struts forwardin/redirect idea

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Instead of having to specify in every <forward..> tag, can you add
> functionality that uses a "default" init parameter as the "default" flag to
> foward or redirect. By this I mean, allow an init parameter in web.xml that
> specifies if ALL forwarding should be done via redirects, or forwarding via
> RequestDispatcher. This way, I can change the functionality of ALL redirects
> in one place..if need be. To add to this, IF (and only if) the redirect=".."
> exists in the <forward tag>, does it OVERRIDE the "init" value. I find it
> cumbersome (ok..Im being lazy) to keep typing in "false" for every action.
> But, there is a special case when I would want to use redirects for
> everything, instead of forwarding. For example, our live site uses IIS/JRUN,
> where as I am using Orion to develop the framework on. JRUN supports Servlet
> 2.1, and other than taglibs, I believe the framework will work with Servlet
> 2.1 for forwarding and redirects. The only thing I can see not working is
> the taglibs.
>

The controller servlet and all that stuff should work fine under Servlet 2.1,
because servlet context attributes and RequestDispatcher.forward() were added in
that version.

>
> Anyways..I'd like to hear if others would like this feature too...I think it
> would be great. Or..does it already exist? Should be only a few lines of
> code and it wouldn't break the source at all..just add a feature.
>
> Thanks.

I just checked in a change to make this choice of a global default trivially
easy.

The key is that you can override the name of the ActionForward class that is
actually used by modifying the "forward" initialization parameter to the
ActionServlet servlet.  I just created two subclasses of ActionForward --
ForwardingActionForward and RedirectingActionForward -- and you can pick
whichever one you want as the default.  That way, you don't have to specify the
redirect attribute on any of your <forward> elements if you want the default
value, but you can set it explicitly if necessary for a particular entry.

Now, if you want redirect to be the default mechanism, just add this to your
web.xml file under the controller servlet's <servlet> entry:

    <init-param>
        <param-name>forward</param-name>

<param-value>org.apache.struts.action.RedirectingActionForward</param-value>
    </init-param>

To maintain the current default (using a RequestDIspatcher.forward()), either
leave this parameter out or change the value to
"org.apache.struts.action.ForwardingActionForward" instead.

Craig

PS:  Subclasses are your friends :-)