aspose file tools*
The moose likes Struts and the fly likes Struts2: Dynamically returning to last page shown after an action call from a form submit. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2: Dynamically returning to last page shown after an action call from a form submit." Watch "Struts2: Dynamically returning to last page shown after an action call from a form submit." New topic
Author

Struts2: Dynamically returning to last page shown after an action call from a form submit.

David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi,

I have a collection of pages in a site that hold the same user login form, just 2 fields.

They all call a login method on the same action class but what I would like to do is return to the page where the submit came from.

Is this possible?

Thanks,

Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689


Hi,

First of all define one global variable

private String action;

make getter and setter method for your action variable.

then use
<s:form name=%{action} method="post" >


</s:form>


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
David Rocks
Ranch Hand

Joined: Apr 24, 2001
Posts: 162
Hi Nishan,

I am not sure how that would work.

the form is on many pages but goes to the same action class.

<s:form action="user!login" >
.....<s:textfield name="user.username" size="10" label="username"/>
.....<s:password name="user.password" size="10" label="password"/>
.....<s:submit value="login"/>
</s:form>

Here is my action mapping

<action name="user" class="com.forum.web.UserAction" method="input" >
...<result name="success" >index.jsp</result>
</action>

And as you can see it always goes back to index.jsp but really I want it to go back to the page where the form was displayed ( the same page where the person was on before they used the login form ) and there are many JSPs where this form is displayed

Now I know that you can use a dynamic forward, so if I create a variable fromPage in my UserAction I can then make my action mapping..

<action name="user" class="com.forum.web.UserAction" method="input" >
...<result name="success" >%{fromPage }</result>
</action>

But it is populating that variable with the Action that I use to to create the jsp which shows the login form. I can easily pass in the JSP path in a hidden variable but all JSPs are created after an Action class call.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2: Dynamically returning to last page shown after an action call from a form submit.