環境: struts包版本:struts-core-2.1.6
filter配置:
JSP頁面均已配置:contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
struts.xml 無論是否加入: <constant name="struts.i18n.encoding" value="GBK" />
過程:通過index頁面上form表單向result頁面發送中文字符請求
結果:
method="GET" 亂碼 無論是form中設置method還是瀏覽器輸入
method="POST" 正確中文
總結:在web.xml中,將struts2配置爲org.apache.struts2.dispatcher.FilterDispatcher時,post請求均可很好的自動解決中文亂碼問題,get一律報錯(在不借助其他方法進行手動重編碼的情況下)
在web.xml中,將struts2配置爲org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter時,無論如何中文均報BUG,據官方解釋此爲BUG, struts 2.1.7後進行了修復
結論: 在2.1.7之前,結果中文亂碼問題,最好自行編寫CharactorEncodingFilter進行編碼。
若試圖使用上述中的FilterDispatcher解決中文問題,則會連帶產生由於Filter版本不同而帶來的多種問題,其一便是自定義Action中利用ActionContext.getContext.get("request")引發空指針的問題
相關資源:http://topic.csdn.net/u/20081029/14/ea380205-ae9a-4ad0-9a7d-5ab1b09a1908.html