You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Juan Gargiulo <ju...@mindstech.com> on 2000/09/15 02:29:05 UTC

ActionClass chaining

Hi,
Struts defines that an Action class processes the request and returns the
control to a JSP (defined by the ActionForward object). But it is correct to
forward the control to another ActionClass? What if we need to perform
different logic to go from one page to the other?

One example scenario where this is required could be the following:
-loginPage -> Controller -> LogonAction (User validation) -> HomePageAction
(Home page generation) -> homePage

Thanks in advance for your help,


juan


Re: ActionClass chaining

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

> Craig,
>
> Thanks for your fast reply. Sorry, but I didn't see your example of
> forwarding to an action class because I changed the forwarding of the
> saveSubscription to the mainMenu.jsp in my modified version of your example
> :-)
>

:-)

>
> I wanted to tell you that I just tried struts and I think it's great. I was
> able to learn it in a very short time and struts architecture is really
> going to help me create well structured applications. The company decided to
> implement a prototype of one of the products with struts, so we need to know
> if there is or is going to be soon, a final version.

My goal is to have a 1.0 release (at least in beta, but hopefully finalized) by
ApacheCon Europe, which is October 23-25,2000 in London.  I'm feverishly editing
the TODO list of the things that need to be done (which is why people wanting to
work on developing Struts haven't heard much from me in the last couple of days
:-).

One of the issues I have felt is really important is to maintain as much
backwards compatibility as possible as Struts has developed.  However, there are
likely to be some backwards-incompatible changes when 1.0 comes out.  I won't be
removing any existing functionality -- but it will need to be utilized in
slightly different ways.

One of the top-level goals for 1.0 is getting the APIs nailed down so that we
can extend the Struts framework in the future, without breaking backwards
compatibility after 1.0.

>
> I also wanted to ask you about something that I couldn't figure out yet how
> to solve it properly. The problem is with refreshing pages. Sometimes the
> user is on a certain page that contains a form, and after submitting the
> form, they go to another page, but their url is still pointing to the url
> that processed the form. So if they refresh the page, they will be sending
> the form info again to the url that processed this form, and this is
> something that we don't want.

This is a standard problem with web browsers, and isn't specific to Struts.  One
thing that Struts does offer to help you is a configuration setting on the
ActionServlet servlet.  If you include the following init parameter:

    <init-param>
        <param-name>nocache</param-name>
        <param-value>true</param-value>
    </init-param>

then the controller servlet will set the following three HTTP headers on every
response that was initiated by going through the controller servlet:

    Pragma: No-cache
    Cache-Control: no-cache
    Expires:  <a date/time long in the past>

These headers are designed to convince browsers and proxies not to cache the
original page, so that it will be re-requested from the server.

In general, users of webapps need to be trained to use the navigation controls
provided by the application rather than the browser buttons that they use when
surfing web sites.  But of course that is not always possible, so we need to
provide as much protection as we can against the back button and things like
that.

>
> Thanks again,
>
> juan
>

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



Re: ActionClass chaining

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

> I encountered this problem as well. And it is a big issue if it is a page
> that users may
> want to bookmark...which are many many pages.
>
> I "fixed" this by setting up the mapping (in action.xml) to use redirect,
> add the redirect="true" attribute to the forward tag). Fro example:
>
>    <forward name="success"    path="/index.jsp" redirect="true"/>
>
> But you have to note that a redirect "looses" your request variables and
> so you cant use this when using the "errors" mechanism in struts. Aswell,
> the path for a redirect is compiuted differently than a forward (for a
> forward the path MUST start with a / and is relaitive to the context) but
> for a forward the path is As-IS – thus if it starts with a / it wil miss
> out the context and it wont work unless your context happens to be /.
>

There have been some recommendations about making forwards smarter about
interpreting relative paths the same way (i.e. paths that start with "/" are
context relative), whether it ends up doing a RequestDispatcher.forward or a
HttpServletResponse.sendRedirect.  I think this would solve the problem, right?

>
> Mike Papper
> mpapp@geocities.com

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat



RE: ActionClass chaining

Posted by Juan Gargiulo <ju...@mindstech.com>.
Yes, this is the best solution I could come up with. But I don't like having
to make an extra client redirect just for this. Maybe the page flow can be
designed in a way where this is avoided. And maybe struts provides some
infrastructure for this.

juan



-----Original Message-----
From: Mike Papper [mailto:mpapp@geocities.com]
Sent: Friday, September 15, 2000 12:17 AM
To: struts-user@jakarta.apache.org
Subject: RE: ActionClass chaining


I encountered this problem as well. And it is a big issue if it is a page
that users may
want to bookmark...which are many many pages.

I "fixed" this by setting up the mapping (in action.xml) to use redirect,
add the redirect="true" attribute to the forward tag). Fro example:

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

But you have to note that a redirect "looses" your request variables and
so you cant use this when using the "errors" mechanism in struts. Aswell,
the path for a redirect is compiuted differently than a forward (for a
forward the path MUST start with a / and is relaitive to the context) but
for a forward the path is As-IS – thus if it starts with a / it wil miss
out the context and it wont work unless your context happens to be /.

Mike Papper
mpapp@geocities.com

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 9/14/2000, 6:25:39 PM, "Juan Gargiulo" <ju...@mindstech.com> wrote
regarding RE: ActionClass chaining:


> Craig,

> Thanks for your fast reply. Sorry, but I didn't see your example of
> forwarding to an action class because I changed the forwarding of the
> saveSubscription to the mainMenu.jsp in my modified version of your
example
> :-)

> I wanted to tell you that I just tried struts and I think it's great. I
was
> able to learn it in a very short time and struts architecture is really
> going to help me create well structured applications. The company decided
to
> implement a prototype of one of the products with struts, so we need to
know
> if there is or is going to be soon, a final version.

> I also wanted to ask you about something that I couldn't figure out yet
how
> to solve it properly. The problem is with refreshing pages. Sometimes the
> user is on a certain page that contains a form, and after submitting the
> form, they go to another page, but their url is still pointing to the url
> that processed the form. So if they refresh the page, they will be
sending
> the form info again to the url that processed this form, and this is
> something that we don't want.

> Thanks again,

> juan





> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Thursday, September 14, 2000 5:47 PM
> To: struts-user@jakarta.apache.org
> Subject: Re: ActionClass chaining


> Juan Gargiulo wrote:

> > Hi,
> > Struts defines that an Action class processes the request and returns
the
> > control to a JSP (defined by the ActionForward object). But it is
correct
> to
> > forward the control to another ActionClass? What if we need to perform
> > different logic to go from one page to the other?
> >
> > One example scenario where this is required could be the following:
> > -loginPage -> Controller -> LogonAction (User validation) ->
> HomePageAction
> > (Home page generation) -> homePage
> >

> You can actually do this with the existing version of Struts, by using a
> path
> that resolves to HomePageAction instead of a path to a JSP page, as you
set
> up
> your forward.  When the action servlet executes the
> RequestDispatcher.forward(),
> control will be forwarded back to the controller servlet again -- and the
> second
> action will be performed.

> As far as "correctness" goes, I guess if I used this technique in the
> example
> app it must be OK :-).  If you look at the /saveSubsription action,
you'll
> see
> that I define a <forward> element that has the path
> "/editRegistration.do?action=Edit" -- which causes two actions in a row
to
> be
> executed before control is ultimately returned to the JSP page.

> >
> > Thanks in advance for your help,
> >
> > juan

> Craig

> ====================
> See you at ApacheCon Europe <http://www.apachecon.com>!
> Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
> Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
>                                     Applications to Tomcat


RE: ActionClass chaining

Posted by Mike Papper <mp...@geocities.com>.
I encountered this problem as well. And it is a big issue if it is a page 
that users may
want to bookmark...which are many many pages.

I "fixed" this by setting up the mapping (in action.xml) to use redirect, 
add the redirect="true" attribute to the forward tag). Fro example:

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

But you have to note that a redirect "looses" your request variables and 
so you cant use this when using the "errors" mechanism in struts. Aswell, 
the path for a redirect is compiuted differently than a forward (for a 
forward the path MUST start with a / and is relaitive to the context) but 
for a forward the path is As-IS – thus if it starts with a / it wil miss 
out the context and it wont work unless your context happens to be /.

Mike Papper
mpapp@geocities.com

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 9/14/2000, 6:25:39 PM, "Juan Gargiulo" <ju...@mindstech.com> wrote 
regarding RE: ActionClass chaining:


> Craig,

> Thanks for your fast reply. Sorry, but I didn't see your example of
> forwarding to an action class because I changed the forwarding of the
> saveSubscription to the mainMenu.jsp in my modified version of your 
example
> :-)

> I wanted to tell you that I just tried struts and I think it's great. I 
was
> able to learn it in a very short time and struts architecture is really
> going to help me create well structured applications. The company decided 
to
> implement a prototype of one of the products with struts, so we need to 
know
> if there is or is going to be soon, a final version.

> I also wanted to ask you about something that I couldn't figure out yet 
how
> to solve it properly. The problem is with refreshing pages. Sometimes the
> user is on a certain page that contains a form, and after submitting the
> form, they go to another page, but their url is still pointing to the url
> that processed the form. So if they refresh the page, they will be 
sending
> the form info again to the url that processed this form, and this is
> something that we don't want.

> Thanks again,

> juan





> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Thursday, September 14, 2000 5:47 PM
> To: struts-user@jakarta.apache.org
> Subject: Re: ActionClass chaining


> Juan Gargiulo wrote:

> > Hi,
> > Struts defines that an Action class processes the request and returns the
> > control to a JSP (defined by the ActionForward object). But it is correct
> to
> > forward the control to another ActionClass? What if we need to perform
> > different logic to go from one page to the other?
> >
> > One example scenario where this is required could be the following:
> > -loginPage -> Controller -> LogonAction (User validation) ->
> HomePageAction
> > (Home page generation) -> homePage
> >

> You can actually do this with the existing version of Struts, by using a
> path
> that resolves to HomePageAction instead of a path to a JSP page, as you 
set
> up
> your forward.  When the action servlet executes the
> RequestDispatcher.forward(),
> control will be forwarded back to the controller servlet again -- and the
> second
> action will be performed.

> As far as "correctness" goes, I guess if I used this technique in the
> example
> app it must be OK :-).  If you look at the /saveSubsription action, 
you'll
> see
> that I define a <forward> element that has the path
> "/editRegistration.do?action=Edit" -- which causes two actions in a row 
to
> be
> executed before control is ultimately returned to the JSP page.

> >
> > Thanks in advance for your help,
> >
> > juan

> Craig

> ====================
> See you at ApacheCon Europe <http://www.apachecon.com>!
> Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
> Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
>                                     Applications to Tomcat

RE: ActionClass chaining

Posted by Juan Gargiulo <ju...@mindstech.com>.
Craig,

Thanks for your fast reply. Sorry, but I didn't see your example of
forwarding to an action class because I changed the forwarding of the
saveSubscription to the mainMenu.jsp in my modified version of your example
:-)

I wanted to tell you that I just tried struts and I think it's great. I was
able to learn it in a very short time and struts architecture is really
going to help me create well structured applications. The company decided to
implement a prototype of one of the products with struts, so we need to know
if there is or is going to be soon, a final version.

I also wanted to ask you about something that I couldn't figure out yet how
to solve it properly. The problem is with refreshing pages. Sometimes the
user is on a certain page that contains a form, and after submitting the
form, they go to another page, but their url is still pointing to the url
that processed the form. So if they refresh the page, they will be sending
the form info again to the url that processed this form, and this is
something that we don't want.

Thanks again,

juan





-----Original Message-----
From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Thursday, September 14, 2000 5:47 PM
To: struts-user@jakarta.apache.org
Subject: Re: ActionClass chaining


Juan Gargiulo wrote:

> Hi,
> Struts defines that an Action class processes the request and returns the
> control to a JSP (defined by the ActionForward object). But it is correct
to
> forward the control to another ActionClass? What if we need to perform
> different logic to go from one page to the other?
>
> One example scenario where this is required could be the following:
> -loginPage -> Controller -> LogonAction (User validation) ->
HomePageAction
> (Home page generation) -> homePage
>

You can actually do this with the existing version of Struts, by using a
path
that resolves to HomePageAction instead of a path to a JSP page, as you set
up
your forward.  When the action servlet executes the
RequestDispatcher.forward(),
control will be forwarded back to the controller servlet again -- and the
second
action will be performed.

As far as "correctness" goes, I guess if I used this technique in the
example
app it must be OK :-).  If you look at the /saveSubsription action, you'll
see
that I define a <forward> element that has the path
"/editRegistration.do?action=Edit" -- which causes two actions in a row to
be
executed before control is ultimately returned to the JSP page.

>
> Thanks in advance for your help,
>
> juan

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat




Re: ActionClass chaining

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

> Hi,
> Struts defines that an Action class processes the request and returns the
> control to a JSP (defined by the ActionForward object). But it is correct to
> forward the control to another ActionClass? What if we need to perform
> different logic to go from one page to the other?
>
> One example scenario where this is required could be the following:
> -loginPage -> Controller -> LogonAction (User validation) -> HomePageAction
> (Home page generation) -> homePage
>

You can actually do this with the existing version of Struts, by using a path
that resolves to HomePageAction instead of a path to a JSP page, as you set up
your forward.  When the action servlet executes the RequestDispatcher.forward(),
control will be forwarded back to the controller servlet again -- and the second
action will be performed.

As far as "correctness" goes, I guess if I used this technique in the example
app it must be OK :-).  If you look at the /saveSubsription action, you'll see
that I define a <forward> element that has the path
"/editRegistration.do?action=Edit" -- which causes two actions in a row to be
executed before control is ultimately returned to the JSP page.

>
> Thanks in advance for your help,
>
> juan

Craig

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat