Struts 2: return to calling page

I'm using Struts 2.

I'd like to return from an Action to the page which invoked it.

Say I'm in page x.jsp, I invoke Visual action to change CSS preferences in the session; I want to return to x.jsp rather than to a fixed page (i.e. home.jsp)

Here's the relevant struts.xml fragment:

<action
   name="Visual"
   class="it.___.web.actions.VisualizationAction">
   <result name="home">/pages/home.jsp</result>
</action>

Of course my VisualizationAction.execute() returns home.

Is there any "magic" constant (like, say, INPUT_PAGE) that I may return to do the trick?

Must I use a more involved method (i.e. extracting the request page and forwarding to it)?

T.I.A.

Answers


You can use a dynamic result in struts.xml. For instance:

<action
   name="Visual"
   class="it.___.web.actions.VisualizationAction">
   <result name="next">${next}</result>
</action>

Then in your action, you create a field called next. So to invoke the action you will pass the name of the page that you want to forward to next. The action then returns "next" and struts will know which page to go to.

There is a nicer explanation on this post: Stack Overflow


Need Your Help

PHP MySQL New Lines / Whitespaces from textarea

php mysql json

I've a problem about whitespaces and new lines at the beginning of a textarea.

Technology advice - Tablet based web application - (Platform independent) -Sort Of Enterprise Management System

php jquery html5 jquery-mobile drupal-7

I'm planning to develop a tablet based web application that is compatible on all platforms (iOS, Android, Blackberry etc). I need your advice in choosing the right technology.