{"id":294,"date":"2007-04-26T17:01:05","date_gmt":"2007-04-26T09:01:05","guid":{"rendered":"http:\/\/www.jason695.idv.tw:81\/wordpress\/?p=294"},"modified":"2007-05-02T12:05:48","modified_gmt":"2007-05-02T04:05:48","slug":"%e8%bd%89%e8%b2%bc-struts%e4%b8%ad%e6%96%87%e5%95%8f%e9%a1%8c%ef%bc%8cstruts%e5%9c%8b%e9%9a%9b%e5%8c%96%e5%95%8f%e9%a1%8c%e2%80%94%e2%80%94%e7%b5%82%e6%a5%b5%e8%a7%a3%e6%b1%ba%e6%96%b9","status":"publish","type":"post","link":"https:\/\/jason695.why3s.tw\/wordpress\/2007\/04\/26\/%e8%bd%89%e8%b2%bc-struts%e4%b8%ad%e6%96%87%e5%95%8f%e9%a1%8c%ef%bc%8cstruts%e5%9c%8b%e9%9a%9b%e5%8c%96%e5%95%8f%e9%a1%8c%e2%80%94%e2%80%94%e7%b5%82%e6%a5%b5%e8%a7%a3%e6%b1%ba%e6%96%b9\/","title":{"rendered":"[\u8f49\u8cbc] &#8220;struts\u4e2d\u6587\u554f\u984c&#8221;\uff0c&#8221;struts\u570b\u969b\u5316\u554f\u984c&#8221;\u2014\u2014\u7d42\u6975\u89e3\u6c7a\u65b9\u6848"},"content":{"rendered":"<p>\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<br \/>\n\u5f15\u6587<br \/>\n\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<br \/>\n\u8aaa\u5be6\u8a71\uff0c\u4f60\u5011\u7684\u65b9\u6cd5\u90fd\u505a\u7684\u8907\u96dc\u4e86\uff0cJava\u672c\u8eab\u5c31\u652f\u63f4\u591a\u570b\u8a9e\u8a00\u7de8\u78bc\uff0c\u4e0d\u9700\u8981\u5beb\u4efb\u4f55\u7a0b\u5f0f\uff0c\u53ef\u4ee5\u5f88\u7c21\u55ae\u7684<br \/>\n\u5be6\u73fe\u3002<br \/>\n\u79d8\u8a23\u5c31\u662f\u5169\u9ede\uff1a<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> 1\u3001\u6240\u6709HTML\/JSP\u9801\u9762\u5168\u90e8\u63a1\u7528UTF-8\u7de8\u78bc<br \/>\n2\u3001\u7528\u6236\u7aef\u6d41\u89bd\u5668\u5b8c\u5168\u652f\u63f4UTF-8\u7de8\u78bc<\/p><\/blockquote>\n<p>\u6b65\u9a5f\uff1a<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> 1\u3001\u9996\u5148\u628a\u6240\u6709\u7684HTML\/JSP\u7684ContentType\u90fd\u8a2d\u70baUTF-8<br \/>\n2\u3001\u7136\u5f8c\u5c0d\u65bcJSP\u7a0b\u5f0f\u4e2d\u7684\u975eASCII\u78bc\u63d0\u793a\u8cc7\u8a0a\u90fd\u4e0d\u61c9\u8a72\u5beb\u5728\u7a0b\u5f0f\u88cf\u9762\uff0c\u90fd\u61c9\u8a72\u653e\u5728<br \/>\napplication.properties\u88cf\u9762\u7d71\u4e00\u7ba1\u7406\u3002<br \/>\n3\u3001\u5c0dHTML\u7528native2ascii\u5de5\u5177\u7d71\u4e00\u505a\u4e00\u6b21\u8655\u7406\uff0c\u628aHTML\u4e2d\u7684\u975eASCII\u78bc\u90fd\u8f49\u63db\u70baUnicode\u7de8\u78bc\u3002<br \/>\n4\u3001\u91dd\u5c0d\u4e0d\u540c\u7684\u8a9e\u8a00\uff0c\u5beb\u4e0d\u540c\u7684application.properties\uff0c\u6bd4\u5982\u8aaa\u7c21\u9ad4\u4e2d\u6587\u662f<br \/>\napplication_zh_CN.properties\uff0c\u7e41\u9ad4\u4e2d\u6587\u662fapplication_zh_TW.properties\u9019\u6a23\uff0c\u7136\u5f8c\u5c0d\u9019\u4e9b\u914d\u7f6e\u4fe1<br \/>\n\u606f\u6a94\u540c\u6a23\u7528native2ascii\u5de5\u5177\u8655\u7406\u4e00\u6b21\uff0c\u628a\u975eASCII\u78bc\u7d71\u7d71\u8f49\u70baUnicode\u7de8\u78bc\u3002<br \/>\n5\u3001\u5728Servlet\u7684request.getCharacterEncoding()\u7372\u5f97\u7528\u6236\u7aef\u7684\u4f5c\u696d\u7cfb\u7d71\u9ed8\u8a8d\u7de8\u78bc\uff0c\u7136\u5f8cset\u5230Struts<br \/>\n\u7684HTTPSession\u7684Locale\u4e2d\u3002<\/p><\/blockquote>\n<p>OK\uff01\u73fe\u5728\u4e0d\u540c\u7684\u5ba2\u6236\u8a2a\u554f\uff0c\u5c31\u6703\u986f\u793a\u4e0d\u540c\u7684\u8a9e\u8a00\u7248\u672c\u4e86\u3002\u4f60\u53ef\u4ee5\u770b\u770b\u6b64\u6642\u4f60\u7684\u6d41\u89bd\u5668\u7684\u5b57\u5143\u96c6\uff0c\u5c31\u662f<br \/>\nUTF-8\u3002\u73fe\u5728\u4f60\u7684\u7db2\u7ad9\u548cGoogle\u4e00\u6a23\u4e86\uff0c\u563f\u563f\uff0c\u5176\u5be6\u4f60\u6709\u5fc3\u7684\u8a71\uff0c\u770b\u770b\u4f60\u7684\u6d41\u89bd\u5668\u8a2a\u554fGoogle\u7684\u6642\u5019\u662f<br \/>\n\u4ec0\u9ebc\u5b57\u5143\u96c6\u5427<br \/>\n\u5207\u8a18\uff1a\u6240\u6709\u7684HTML\/JSP\u90fd\u8981\u8a2d\u70baUTF-8\u7de8\u78bc\uff0c\u6240\u6709\u7684\u6a94\u4e2d\u7684\u975eASCII\u78bc\u5b57\u5143\u90fd\u8981\u7528native2ascii\u5de5\u5177\u8f49<br \/>\n\u70ba\u7528ASCII\u8868\u793a\u7684Unicode\u7de8\u78bc\u3002<\/p>\n<p>\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<br \/>\n\u539f\u5275<br \/>\n\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d<br \/>\n\u4e0a \u9762\u6240\u8ff0\u662f\u6211\u5f9e\u7db2\u4e0a\u4e0b\u7684\u4e00\u7bc7\u4e8e\u4e2d\u6587\u554f\u984c\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u78ba\u5207\u7684\u8aaa\u61c9\u8a72\u662f\u95dc\u65bcStruts\u7684\u570b\u969b\u5316\u554f\u984c\uff0c<br \/>\n\u4e0b\u9762\u6211\u7d50\u5408\u6211\u7684\u5be6\u8e10\u8ac7\u8ac7\u5177\u9ad4\u5982\u4f55\u5be6\u73feStruts\u7684\u570b\u969b\u5316 \u554f\u984c\uff0c\u6211\u5c0d\u7406\u8ad6\u4e0d\u662f\u975e\u5e38\u7cbe\u901a\uff0c<br \/>\n\u6211\u53ea\u80fd\u5b8c\u5168\u6191\u81ea\u5df1\u7684\u7406\u89e3\u548c\u5be6\u8e10\u4f86\u8b1b\u8ff0\uff0c\u6240\u4ee5\u4e0b\u9762\u8b1b\u7684\u5167\u5bb9\u53ef\u80fd\u4e0d\u662f\u975e\u5e38\u6b63\u78ba\uff0c<br \/>\n\u9084\u8acb\u5927\u5bb6\u539f\u8ad2\u3002\u4f46\u6709\u4e00\u9ede\u53ef\u4ee5\u80af\u5b9a\uff0c\u6211\u901a\u904e\u81ea\u5df1\u7684\u52aa \u529b\u89e3\u6c7a\u4e86Struts\u7684\u4e2d\u6587\u554f\u984c\uff0c<br \/>\n\u4e26\u5be6\u73feStruts\u7684\u570b\u969b\u5316\uff0c\u5176\u5be6\u4e00\u5207\u4e26\u4e0d\u8907\u96dc\uff0c\u4e0b\u9762\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<br \/>\n0.\u9047\u5230\u7684\u554f\u984c(\u9019\u4e9b\u554f\u984c\u4e5f\u8a31\u4e0d\u6703\u540c\u6642\u51fa\u73fe)<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> a.\u4e2d\u6587\u8cc7\u6599\u5f9e\u8cc7\u6599\u5eab\u4e2d\u5230jsp\u4e2d\u5f8c\u5c31\u8b8a\u6210\u4e86&#8221;????&#8221;<br \/>\nb.\u505a\u597d\u7684\u4e2d\u6587properties\u6a94\uff0c\u5176\u4e2d\u7684\u4e2d\u6587value\u5728\u9801\u9762\u986f\u793a\u4e82\u78bc<br \/>\nc.jsp\u6a94\u4e2d\u7684\u4e2d\u6587\u5230\u6d41\u89bd\u5668\u5f8c\u986f\u793a\u6642\u4e5f\u662f\u4e82\u78bc\uff08\u5efa\u8b70\u4e0d\u8981\u5728jsp\u6a94\u4e2d\u8f38\u5165\u4e2d\u6587\uff0c\u5118\u91cf\u653e\u5728properties\u6a94\u4e2d\uff09<br \/>\nd.\u7531jsp\u50b3\u7d66bean\u7684\u4e2d\u6587\u503c\uff0c\u518d\u7531bean\u50b3\u56de\u9801\u9762\u53c8\u662f\u4e82\u78bc<br \/>\ne.\u7576\u66f4\u63db\u672c\u5730\u6d41\u89bd\u5668\u7684\u8a9e\u8a00\u9078\u9805\u6642\uff0cWeb\u61c9\u7528\u7a0b\u5f0f\u4e0d\u80fd\u81ea\u52d5\u6839\u64da\u4f60\u7684locale\u9078\u64c7\u5408\u9069\u7684*.properties\u6587\u4ef6\u3002\u5c0e\u81f4Web\u61c9\u7528\u7a0b\u5f0f\u4e0d\u80fd\u570b\u969b\u5316\u3002<\/p><\/blockquote>\n<p>1.\u74b0\u5883\uff1a<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> Web\u4f3a\u670d\u5668\uff1a Tomcat 5.0.19<br \/>\n\u4f5c\u696d\u7cfb\u7d71\uff1a Win2000 Server<br \/>\nJVM   \uff1a jdk 1.4<br \/>\n\u6578 \u64da \u5eab\uff1a Oracle 8.1.7<br \/>\n\u958b\u767c\u5de5\u5177\uff1a struts studio 5.2 pro   for  eclipse<\/p><\/blockquote>\n<p>2.\u5148\u5c07\u6240\u6709*.jsp \u7db2\u9801\u4e2d\u958b\u982d\u8655\u52a0\u5165<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> &lt;%@ page language=&#8221;java&#8221; contentType=&#8221;text\/html; charset=utf-8&#8243; %&gt;<br \/>\n\u518d\u8a2d\u7f6e&lt;html:html locale = &#8220;true&#8221;&gt;<\/p><\/blockquote>\n<p>3.\u7136\u5f8c\u7de8\u8f2f\u597d\u5169\u500b*.properties\u6a94\uff0c\u653e\u5728classes\u6a94\u593e\u4e0b\u4f60\u6307\u5b9a\u7684\u5730\u65b9\uff0c\u9019\u88cf\u662f\u653e\u5728\/web-inf\/classes\/com\/wiley \u4e0b\uff0c\u5b83\u5011\u5206\u5225\u662f\uff1a<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> ApplicationResources.properties  (\u82f1\u6587\u8cc7\u6e90\u6a94\u6848)<br \/>\nApplicationResources_zh.properties (\u4e2d\u6587\u8cc7\u6e90\u6a94\u6848)<br \/>\n\u96a8\u4fbf\u7528\u4ec0\u9ebc\u5de5\u5177\u7de8\u5beb\u90fd\u884c\u554a\uff01<\/p><\/blockquote>\n<p>4.\u5c07ApplicationResources_zh.properties\u8f49\u78bc\u6210gb2312\u3002\u4e0a\u9762\u5f15\u6587\u8aaa\u8981\u8f49\u6210UTF-8\uff0c\u7d50\u679c\u6211\u8a66\u4e86\uff0c\u4e0d\u884c\u3002\u8f49\u6210gb2312\u5c31\u884c\u4e86\uff0c\u64cd\u4f5c\u662f\u3002<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> \u5c07ApplicationResources_zh.properties\u66f4\u540d\u70baApplicationResources_xx.properties<br \/>\n\u5728DOS\u547d\u4ee4\u884c\u9032\u5165ApplicationResources_xx.properties\u6240\u5728\u7684\u6587\u4ef6\u593e<br \/>\n\u4f7f\u7528\u547d\u4ee4\uff1anative2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties(\u81f3\u65bc\u4f60\u70ba\u4ec0\u9ebc\u6703\u51fa\u73fe\u201cnative2ascii\u4e0d\u662f\u5167\u90e8\u547d\u4ee4\u201d\uff0c\uff0c\u8acb\u67e5\u5176\u4ed6\u8cc7 \u6599\uff0c\u53ef\u80fd\u4f60\u8981\u8a2d\u7f6e\u74b0\u5883\u8b8a\u6578\uff0c\u56e0\u70ba\u4ed6\u662fjdk\u7684\u6a94\u593ebin\u4e0b\u7684\u4e00\u500b\u61c9\u7528\u7a0b\u5f0f)<\/p><\/blockquote>\n<p>5.\u63a5\u4e0b\u4f86\u914d\u7f6estruts-config.xml,\u5f88\u7c21\u55ae\uff0c\u6211\u5011\u52a0\u5165\uff1a<\/p>\n<blockquote><\/blockquote>\n<blockquote><p> &lt;message-resources parameter=&#8221;com.wiley.ApplicationResources&#8221;\/&gt;  \u5c31\u884c\u4e86\uff1b<br \/>\n\u5230\u6b64\u5df2\u80fd\u89e3\u6c7a\u5927\u591a\u6578\u4e2d\u6587\u554f\u984c\u3002\u5982\u4e0a\u9762\u6240\u8aaa\u7684a,b,e \u73fe\u5728\u6253\u958b\u6d41\u89bd\u5668\uff0c\u9078\u64c7\u529f\u80fd\u8868\uff1a\u5de5\u5177\u300binternet\u9078\u9805\u300b\u8a9e\u8a00\uff0c\u5c07\u201c\u4e2d\u6587\uff0d\u4e2d\u570b[zh-cn]\u201d\u522a\u6389\uff0c\u6dfb\u52a0\u4e00\u500b\u201c\u82f1\u8a9e\uff0d\u82f1\u570b[zh-gb]\u201d\u78ba\u5b9a\u5f8c\uff0c\u91cd\u555f Tomcat,\u8f38\u5165\u7db2\u5740\u4f60\u5c31\u6703\u767c\u73fe\uff0c\u4f60\u7684\u9801\u9762\u7684\u6587\u672c\u8cc7\u8a0a\u5c31\u6703\u7528\u7684\u662fApplicationResources.properties  (\u82f1\u6587\u8cc7\u6e90\u6a94\u6848)\u4e2d\u7684\u5167\u5bb9\u3002\u5982\u679c\u63db\u56de\u201c\u4e2d\u6587\uff0d\u4e2d\u570b[zh-cn]\u201d\uff0c\u5b83\u5c31\u6703\u986f\u793aApplicationResources_zh.properties (\u4e2d\u6587\u8cc7\u6e90\u6a94\u6848)\u4e2d\u7684\u4e2d\u6587\u5167\u5bb9\u3002<\/p><\/blockquote>\n<p>\u81f3\u65bc\u554f\u984c\u201cc.jsp\u6a94\u4e2d\u7684\u4e2d\u6587\u5230\u6d41\u89bd\u5668\u5f8c\u986f\u793a\u6642\u4e5f\u662f\u4e82\u78bc\u201d \u4f60\u5c31\u8981\u7528\u8207\u7b2c4\u6b65\u985e\u4f3c\u7684\u65b9\u6cd5\u4f86\u91cd\u65b0\u5c0d*.jsp \u6a94\u7de8\u78bc\uff0c\u9019\u6642-encoding\u7684\u53c3\u6578\u5c31\u8981\u7528UTF-8\u4e86\uff0c\u5982\u679c\u4f60\u7528\u7684\u4e5f\u662fstruts studio 5.2 pro   for  eclipse\u5de5\u5177\uff0c\u9019\u4e00\u6b65\u5c31\u514d\u4e86\u3002\u5b83\u6703\u81ea\u52d5\u7528UTF-8\u7684\u683c\u5f0f\u5b58\u5132\u3002<br \/>\n\u81f3\u65bc\u554f\u984c\u201cd.\u7531jsp\u50b3\u7d66bean\u7684\u4e2d\u6587\u503c\uff0c\u518d\u7531bean\u50b3\u56de\u9801\u9762\u53c8\u662f\u4e82\u78bc\u201d\u7684\u89e3\u6c7a\uff0c\u6211\u53ea\u662f\u52a0\u4e86\u500b\u7be9\u6aa2\u7a0b\u5f0f\u3002<br \/>\n\u4f60\u53ef\u4ee5\u73fe\u5728web.xml\u4e2d\u52a0\u5165\uff1a<br \/>\n&lt;filter&gt;<br \/>\n&lt;filter-name&gt;Set Character Encoding&lt;\/filter-name&gt;<br \/>\n&lt;filter-class&gt;com.wiley.SetCharacterEncodingFilter&lt;\/filter-class&gt;<br \/>\n&lt;init-param&gt;<br \/>\n&lt;param-name&gt;encoding&lt;\/param-name&gt;<br \/>\n&lt;param-value&gt;utf-8&lt;\/param-value&gt;<br \/>\n&lt;\/init-param&gt;<br \/>\n&lt;init-param&gt;<br \/>\n&lt;param-name&gt;ignore&lt;\/param-name&gt;<br \/>\n&lt;param-value&gt;true&lt;\/param-value&gt;<br \/>\n&lt;\/init-param&gt;<br \/>\n&lt;\/filter&gt;<br \/>\n&lt;filter-mapping&gt;<br \/>\n&lt;filter-name&gt;Set Character Encoding&lt;\/filter-name&gt;<br \/>\n&lt;servlet-name&gt;action&lt;\/servlet-name&gt;<br \/>\n&lt;\/filter-mapping&gt;<\/p>\n<p>\u7136\u5f8c\u5728\u4f60\u6307\u5b9a\u7684\u5305\u5167\u52a0\u500bjava\u6587\u4ef6 \u6211\u653e\u5728\u4e86\/web-inf\/classes\/com\/wiley \u88cf\uff0c\u4e0b\u9762\u662f\u6e90\u4ee3\u78bc\uff1a<br \/>\n\/*<br \/>\n* XP Forum<br \/>\n*<br \/>\n* Copyright (c) 2002-2003 RedSoft Group. All rights reserved.<br \/>\n*<br \/>\n*\/<br \/>\npackage com.huahang.tj.struts.filters;<br \/>\nimport javax.servlet.*;<br \/>\nimport java.io.IOException;<br \/>\n\/**<br \/>\n* &lt;p&gt;Filter that sets the character encoding to be used in parsing the<br \/>\n* incoming request, either unconditionally or only if the client did not<br \/>\n* specify a character encoding. Configuration of this filter is based on<br \/>\n* the following initialization parameters:&lt;\/p&gt;<br \/>\n* &lt;ul&gt;<br \/>\n* &lt;li&gt;&lt;strong&gt;encoding&lt;\/strong&gt; &#8211; The character encoding to be configured<br \/>\n* for this request, either conditionally or unconditionally based on<br \/>\n* the &lt;code&gt;ignore&lt;\/code&gt; initialization parameter. This parameter<br \/>\n* is required, so there is no default.&lt;\/li&gt;<br \/>\n* &lt;li&gt;&lt;strong&gt;ignore&lt;\/strong&gt; &#8211; If set to &#8220;true&#8221;, any character encoding<br \/>\n* specified by the client is ignored, and the value returned by the<br \/>\n* &lt;code&gt;selectEncoding()&lt;\/code&gt; method is set. If set to &#8220;false,<br \/>\n* &lt;code&gt;selectEncoding()&lt;\/code&gt; is called &lt;strong&gt;only&lt;\/strong&gt; if the<br \/>\n* client has not already specified an encoding. By default, this<br \/>\n* parameter is set to &#8220;true&#8221;.&lt;\/li&gt;<br \/>\n* &lt;\/ul&gt;<br \/>\n*<br \/>\n* &lt;p&gt;Although this filter can be used unchanged, it is also easy to<br \/>\n* subclass it and make the &lt;code&gt;selectEncoding()&lt;\/code&gt; method more<br \/>\n* intelligent about what encoding to choose, based on characteristics of<br \/>\n* the incoming request (such as the values of the &lt;code&gt;Accept-Language&lt;\/code&gt;<br \/>\n* and &lt;code&gt;User-Agent&lt;\/code&gt; headers, or a value stashed in the current<br \/>\n* user&#8217;s session.&lt;\/p&gt;<br \/>\n*<br \/>\n* @author &lt;a href=&#8221;mailto:jwtronics@yahoo.com&#8221;&gt;John Wong&lt;\/a&gt;<br \/>\n*<br \/>\n* @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002\/04\/10 13:59:27 johnwong Exp $<br \/>\n*\/<br \/>\npublic class SetCharacterEncodingFilter implements Filter {<br \/>\n\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; Instance Variables<\/p>\n<p>\/**<br \/>\n* The default character encoding to set for requests that pass through<br \/>\n* this filter.<br \/>\n*\/<br \/>\nprotected String encoding = null;<\/p>\n<p>\/**<br \/>\n* The filter configuration object we are associated with. If this value<br \/>\n* is null, this filter instance is not currently configured.<br \/>\n*\/<br \/>\nprotected FilterConfig filterConfig = null;<\/p>\n<p>\/**<br \/>\n* Should a character encoding specified by the client be ignored?<br \/>\n*\/<br \/>\nprotected boolean ignore = true;<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Public Methods<\/p>\n<p>\/**<br \/>\n* Take this filter out of service.<br \/>\n*\/<br \/>\npublic void destroy() {<br \/>\nthis.encoding = null;<br \/>\nthis.filterConfig = null;<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Select and set (if specified) the character encoding to be used to<br \/>\n* interpret request parameters for this request.<br \/>\n*<br \/>\n* @param request The servlet request we are processing<br \/>\n* @param result The servlet response we are creating<br \/>\n* @param chain The filter chain we are processing<br \/>\n*<br \/>\n* @exception IOException if an input\/output error occurs<br \/>\n* @exception ServletException if a servlet error occurs<br \/>\n*\/<br \/>\npublic void doFilter(ServletRequest request, ServletResponse response,<br \/>\nFilterChain chain)<br \/>\nthrows IOException, ServletException {<br \/>\n\/\/ Conditionally select and set the character encoding to be used<br \/>\nif (ignore || (request.getCharacterEncoding() == null)) {<br \/>\nString encoding = selectEncoding(request);<br \/>\nif (encoding != null)<br \/>\nrequest.setCharacterEncoding(encoding);<br \/>\n}<br \/>\n\/\/ Pass control on to the next filter<br \/>\nchain.doFilter(request, response);<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Place this filter into service.<br \/>\n*<br \/>\n* @param filterConfig The filter configuration object<br \/>\n*\/<br \/>\npublic void init(FilterConfig filterConfig) throws ServletException {<br \/>\nthis.filterConfig = filterConfig;<br \/>\nthis.encoding = filterConfig.getInitParameter(&#8220;encoding&#8221;);<br \/>\nString value = filterConfig.getInitParameter(&#8220;ignore&#8221;);<br \/>\nif (value == null)<br \/>\nthis.ignore = true;<br \/>\nelse if (value.equalsIgnoreCase(&#8220;true&#8221;))<br \/>\nthis.ignore = true;<br \/>\nelse if (value.equalsIgnoreCase(&#8220;yes&#8221;))<br \/>\nthis.ignore = true;<br \/>\nelse<br \/>\nthis.ignore = false;<br \/>\n}<\/p>\n<p>\/\/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Protected Methods<\/p>\n<p>\/**<br \/>\n* Select an appropriate character encoding to be used, based on the<br \/>\n* characteristics of the current request and\/or filter initialization<br \/>\n* parameters. If no character encoding should be set, return<br \/>\n* &lt;code&gt;null&lt;\/code&gt;.<br \/>\n* &lt;p&gt;<br \/>\n* The default implementation unconditionally returns the value configured<br \/>\n* by the &lt;strong&gt;encoding&lt;\/strong&gt; initialization parameter for this<br \/>\n* filter.<br \/>\n*<br \/>\n* @param request The servlet request we are processing<br \/>\n*\/<br \/>\nprotected String selectEncoding(ServletRequest request) {<br \/>\nreturn (this.encoding);<br \/>\n}<br \/>\n}\/\/EOC<\/p>\n<p>\u5230\u6b64\u6211\u9047\u5230\u7684\u4e2d\u6587\u554f\u984c\u5df2\u5168\u90e8\u5f97\u5230\u89e3\u6c7a\uff0c\u4e26\u5f9e\u4e2d\u7406\u89e3\u5230struts\u7684\u570b\u969b\u5316\u7684\u6df1\u523b\u542b\u7fa9\u3002<br \/>\n\u6211\u500b\u4eba\u89ba\u5f97struts\u4f5c\u70ba\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u6846\u67b6\uff0c\u61c9\u8a72\u65e9\u5c31\u8003\u616e\u5230\u5b83\u7684\u570b\u969b\u5316\u554f\u984c\uff0c\u4e26\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u4e0d\u6703\u5f88\u8907\u96dc\uff0c<br \/>\n\u53ea\u8981\u6211\u5011\u9075\u5faa\u4e00\u4e9b\u898f\u5247\uff0c\u5c31\u53ef\u4ee5\u76e1\u60c5\u4eab\u53d7struts\u7d66\u6211\u5011\u5e36\u4f86\u7684\u7121\u7aae\u6a02\u8da3\u3002\u5e0c\u671b\u4ee5\u4e0a\u6240\u8ff0\u5c0d\u5927\u5bb6\u6709\u6240\u5e6b\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d \u5f15\u6587 \uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d\uff0d &hellip; <a href=\"https:\/\/jason695.why3s.tw\/wordpress\/2007\/04\/26\/%e8%bd%89%e8%b2%bc-struts%e4%b8%ad%e6%96%87%e5%95%8f%e9%a1%8c%ef%bc%8cstruts%e5%9c%8b%e9%9a%9b%e5%8c%96%e5%95%8f%e9%a1%8c%e2%80%94%e2%80%94%e7%b5%82%e6%a5%b5%e8%a7%a3%e6%b1%ba%e6%96%b9\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">[\u8f49\u8cbc] &#8220;struts\u4e2d\u6587\u554f\u984c&#8221;\uff0c&#8221;struts\u570b\u969b\u5316\u554f\u984c&#8221;\u2014\u2014\u7d42\u6975\u89e3\u6c7a\u65b9\u6848<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-java","no-featured-image"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":0,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"wp:attachment":[{"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jason695.why3s.tw\/wordpress\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}