1

I have a Struts 2 web application.

Currently when user click on logout URL, we call a logout action and in the method we call session.invalidate(). If it's success then we are calling logout.jsp.

In logout.jsp we need to redirect to another link. This link is currently hardcoded in JSP.

The link is different in test and production so we have to make changes to this link when we deploy in test & production. We have utility to get values from external file. But since the session is invalidated we are not able to set value in session and retrieve in JSP.

What is the best approach for this?

Roman C
  • 49,761
  • 33
  • 66
  • 176
paramupk
  • 626
  • 1
  • 11
  • 32

2 Answers2

0

You can configure a result before the session is invalidated if you need a session to do that.

Once a result is configured, where you can use a dynamic parameter to the action or URL you want to redirect you no longer need a JSP to perform redirection.

Redirect results can do that without rendering a JSP.

The example is taken from the answer to Redirecting to another action with unknown amount of parameters in Struts 2.

You can also save query string instead of parameter map.

String params = request.getQueryString();

To add parameters dynamically to redirectAction result you should use OGNL in a dynamic parameter.

<param name="actionName">${previousAction.name +'?'+ parameters}</param>

Supposed you have a getter for parameters and initialized it from session where you saved previous query string, action name, and namespace.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • When you say result are you talking about the result in `struts.xml`?? – paramupk Jul 16 '14 at 11:40
  • Not necessarily `struts.xml` it can be convention or other configuration provider result. If you are using xml configuration then use `` tag. See http://stackoverflow.com/a/17838591/573032 – Roman C Jul 16 '14 at 16:28
0

Put the value in the application context on startup and retrieve it from the same place.

There's no reason to put anything in the session that isn't a per-user value.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302