Strutsでリダイレクトのパスにクエリーストリングを追加する
Strutsでは、Action#execute()の返値(ActionForwardオブジェクト)で画面遷移が決定されますが、遷移先のパスにパラメータ(=QueryString)を付加する方法が提供されていないんです。いろいろ探し回った挙げ句、
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=866
にある、ActionRedirectクラスを使用してみました。このように使えます↓
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { (...) ActionRedirect redirect = new ActionRedirect(mapping.findForward("path_to_redirect")); redirect.addParameter("param1", "value1"); redirect.addParameter("param2", 2); redirect.addParameter("param3", 3.0); return redirect; }
ふう。ちょっと反則気味かもしれませんが、必要になるケースは多いと思います。