Struts2で独自に定義したインターセプター内で動的にリダイレクト先を変える処理を書きたかったのだが、色々ハマったのでメモ。
struts.xmlにリダイレクト先を追加。
リダイレクト先はOGNL式で動的に処理できるように定義しておく。
struts.xml
<result name="redirect" type="redirect">
<param name="location">${redirectUrl}</param>
</result>
インターセプター内でリダイレクト先を格納。
/** リダイレクト先URL */
private String redirectUrl;
public String intercept(ActionInvocation invocation) throws Exception {
// 適当な処理
// リダイレクト先のURLをvalueStackに格納
ValueStack valueStack = invocation.getStack();
valueStack.set("redirectUrl",redirectUrl);
return "redirect";
}
参考URL
http://yuroyoro.hatenablog.com/entry/20080414/1208140350
http://stackoverflow.com/questions/173846/struts2-how-to-do-dynamic-url-redirects
http://struts.apache.org/development/2.x/docs/parameters-in-configuration-results.html