リダイレクト時に動的な値をクエリストリングに付与する方法
なんか、ちょっとハマったのでメモ。
Actionなどで動的に生成した値をリダイレクト時にクエリストリングに付与する場合、以下のような書式で書く。
@Result(name = "redirect", path = "RedirectPath?param1=${prop1}", type = "redirect-action", params = { "namespace", "/AnotherNamespace })
path属性の中の${prop1}と書いた部分が、動的な値に置き換わる。
値は、ValueStackの中からOGNLで検索される。
たとえば、bean1.prop1とすると、Actionのbean1プロパティからさらにprop1を取得して置き換える。
また、別のNamespacceのActionに対してRedirectさせたい場合は、paramsに
"namespace","アクションのパス"って感じで追加する。
ってか、ドキュメントにちゃんと書いてあるし。
http://struts.apache.org/2.x/docs/parameters-in-configuration-results.html
Web.xmlでの文字化け対策
Strus2での日本語対応といえば、struts.propertiesのstruts.i18n.encodingプロパティでShift_JISなり指定するのが定番だが、
struts.propertiesに書くことのできる設定値はweb.xmlにも書けるようだ。
web.xmlに、以下のように指定すると、struts.propertiesの定義を
上書きすることができる。
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> <init-param> <param-name>struts.i18n.encoding</param-name> <param-value>Shift_JIS</param-value> </init-param> </filter>