httpheaderについて
httpheaderのResultを使用すると、200以外のステータスコードとカスタムヘッダーを返却することが出来る。
ただし、httpheaderでカスタムヘッダーを出力して、さらにコンテンツを出力するような使い方は出来ない。
異常発生時にエラーをブラウザに返却する場合に使うのだろうか?いまいち使うシーンが良くわからない。。。
struts.xmlに次のようにすると、Actionの戻り値がinputの場合、500エラーとなり、されにクッキーを2つ仕込む。
<action name="user_update" class="UserAction" method="doUpdate"> <param name="preread">true</param> <interceptor-ref name="transactauth_chk"> <param name="scope.session">count,obj</param> <param name="scope.type">end</param> </interceptor-ref> <result type="redirect-action">user_list</result> <result name="input" type="httpheader"> <param name="status">500</param> <param name="headers['Set-Cookie']">${ 'userid=' + id }</param> <param name="headers['Set-Cookie']">${ 'count=' + count }</param> </result> </action>
ちょっとTIPS:cookieは headers.Set-Cookie とは書けなくて、headers['Set-Cookie']と書く
ちょっとTIPS2:OGNL式が掛けるので、ValueStackの値をCookieに設定したり出来る