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.
You can use a dynamic result in struts.xml. For instance:
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