• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,

 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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>

 
David Rocks
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic