{"id":1289,"date":"2016-07-30T08:23:47","date_gmt":"2016-07-30T00:23:47","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1289"},"modified":"2018-03-22T18:04:26","modified_gmt":"2018-03-22T10:04:26","slug":"gwa2-java-i18n","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/gwa2-java-i18n\/","title":{"rendered":"-GWA2 Java\u7248\u672c\u7684i18n\/\u4e2d\u6587\u7f16\u7801\/\u4e71\u7801\u95ee\u9898"},"content":{"rendered":"<p>\u672c\u7bc7\u95ee\u9898\u57df\u88ab\u5b9a\u4e49\u4e3a <a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-gwa2\" target=\"_blank\">-GWA2<\/a> \uff08<a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-\u5409\u5a03\u5154\" target=\"_blank\">-\u5409\u5a03\u5154<\/a>\uff09\u7684 <a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-java\" target=\"_blank\">-Java<\/a> \u7248\u672c\u7684\u591a\u8bed\u8a00\u7684\u7f16\u7801\/\u4e71\u7801\u95ee\u9898\uff0c\u4e5f\u5305\u62ec\u4e2d\u6587\u7684\u7f16\u7801\u548c\u4e71\u7801\u95ee\u9898\u3002\u5f53\u7136\uff0c\u4e5f\u5177\u6709\u666e\u904d\u610f\u4e49\uff0c\u5305\u62ec\u6240\u6709Java\/JSP\u5e94\u7528\u7684\u4e2d\u6587\u7f16\u7801\u3001\u4e71\u7801\u95ee\u9898\u3002<\/p>\n<p><img src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/09\/gwa2-logo-201606.v2.png\" alt=\"gwa2-logo-201606.v2.png (300\u00d7300)\" \/><\/p>\n<p>\u8fd9\u6b21\u8ddd\u79bb\u4e0a\u6b21\u5199Blog\u95f4\u9694\u7684\u65f6\u95f4\u8f83\u957f\uff0c\u4e3b\u8981\u662f\u7531\u4e8e\u53d1\u5e03 -GWA2 Java\u7248\u672c\u5360\u7528\u4e86\u5927\u91cf\u7684\u4e1a\u4f59\u65f6\u95f4\uff08\u5305\u62ec\u71ac\u591c\uff09\uff0c\u6240\u4ee5\u62d6\u4e86\u4e00\u4e9b\u65f6\u95f4\uff0c\u4e2d\u95f4\u7684\u63a2\u7d22\u8fc7\u7a0b(\u5982\u5bf9\u53cd\u5c04\u3001\u5e8f\u5217\u5316\u7684\u76f8\u5173\u601d\u8003\u548c\u5b9e\u9a8c)\u8fd8\u662f\u6709\u503c\u5f97\u8bb0\u5f55\u7684\u5730\u65b9\uff0c\u4eca\u540e\u6162\u6162\u6574\u7406\u3002\u5176\u4e2d\u4e4b\u4e00\u5c31\u662fJava\u7684\u5b57\u7b26\u7f16\u7801\uff0c\u6216\u8005\u518d\u6536\u7a84\u6210Java\u5e94\u7528\u7684\u4e2d\u6587\u5b57\u7b26\u4e71\u7801\u95ee\u9898\u3002 \u7f51\u4e0a\u641c\u7d22Java\u4e2d\u6587\u4e71\u7801\u7684\u5e16\u5b50\u6709\u5f88\u591a\uff0c\u5305\u62ec\u6211\u81ea\u5df1\u51e0\u5e74\u524d\u4e5f\u5199\u4f5c\u8fc7\uff0c\u5982\u57282009-12-10 17:05:14\u53d1\u5e03\u7684\u201c<\/p>\n<h3><a href=\"https:\/\/ufqi.com\/cn\/exp\/x4222.html\" target=\"_blank\">javac\u7f16\u8bd1java\u6587\u4ef6\u4e71\u7801\u7684\u89e3\u51b3\u65b9\u6848<\/a><\/h3>\n<p>\u201d\u8d34\u6587\u548c<a title=\"15:08\" href=\"https:\/\/ufqi.com\/blog\/%e8%bd%ac%ef%bc%9a%e4%b8%ad%e6%96%87%e7%bc%96%e7%a0%81%e6%9d%82%e8%b0%88\/\" rel=\"bookmark\">2014 \u5e74 11 \u6708 21 \u65e5<\/a>\u7684\u201c<\/p>\n<h1><a href=\"https:\/\/ufqi.com\/blog\/%E8%BD%AC%EF%BC%9A%E4%B8%AD%E6%96%87%E7%BC%96%E7%A0%81%E6%9D%82%E8%B0%88\/\" target=\"_blank\">\u4e2d\u6587\u7f16\u7801\u6742\u8c08<\/a><\/h1>\n<p>\u201d\uff0c\u8c08\u4e86\u5728\u4e00\u4e2aJava\u5b9e\u73b0\u7684\u6e38\u620f\u9879\u76ee\u4e2d\u7684\u4e2d\u6587\u7f16\u7801\u95ee\u9898\u53ca\u76f8\u5173\u65b9\u9762\u7684\u77e5\u8bc6\u548c\u95ee\u9898\uff0c\u8fd9\u6b21\u4e4b\u6240\u4ee5\u91cd\u65b0\u8c08\uff0c\u662f\u7acb\u573a\u53d1\u9001\u4e86\u6539\u53d8\uff0c\u4e0d\u53ea\u662f\u89e3\u51b3\u95ee\u9898\uff0c\u800c\u662f\u4ee5\u66f4\u597d\u7684\u65b9\u5f0f\u89e3\u51b3\u95ee\u9898\u2014\u2014<strong>\u6781\u529b\u907f\u514d\u5c06\u5b9d\u8d35\u7684\u8ba1\u7b97\u8d44\u6e90\u7528\u5728\u5b57\u7b26\u8f6c\u7801\u4e0a\uff0c\u5c3d\u91cf\u4e0d\u5728\u5e94\u7528\u4ee3\u7801\u6210\u4f7f\u7528\u5b57\u7b26\u8f6c\u7801\u7684\u65b9\u6cd5\uff0c\u4e0d\u505a\u5b57\u7b26\u8f6c\u7801\u7684\u4e8b\u60c5<\/strong>\u3002 \u8981\u8fd9\u6837\u505a\u5c31\u662f\u521b\u9020\u7edf\u4e00\u7684\u8fd0\u884c\u65f6\u73af\u5883\uff0c\u5305\u62ec\u8f93\u5165\u4e0e\u8f93\u51fa\uff0cJava\u6e90\u7801\u7684i18n\u7684\u7f16\u7801\u662funicode\uff0c\u6211\u4eec\u9009\u62e9\u7684\u7edf\u4e00\u7684\u8fd0\u884c\u65f6\u5b57\u7b26\u7f16\u7801\u662fUTF-8. \u8981\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u8bbe\u8ba1\u5230Webserver\uff08App container\uff09\u3001Java\u7c7b\u3001JSP\u3001HTTP\u548c\u6570\u636e\u5e93\u540e\u53f0\u3001HTML\u524d\u7aef\u7b49\uff0c\u4e0b\u9762\u5206\u522b\u8bb0\u5f55\uff0c\u4ee5\u5f62\u6210\u53ef\u4f9b\u53c2\u8003\u7684\u6587\u6863\u3002<\/p>\n<p><strong>0. Java\u865a\u62df\u673a\u542f\u52a8\u65f6\uff08Webserver\u3001App container\u7b49\uff09<\/strong> \u5728\u547d\u4ee4\u884c\u5e26\u5165\u6307\u5b9a\u5b57\u7b26\u7f16\u7801\u7684\u542f\u52a8\u53c2\u6570 -Dfile.encoding=UTF8<\/p>\n<p><strong>1. JSP\u6587\u4ef6\u9875\u9762\u5934\u90e8\u65f6<\/strong> \u8bbe\u7f6eJSP\u9875\u9762\u7684\u8bed\u8a00\u53ca\u7f16\u7801 &lt;%@page\u00a0language=&#8221;java&#8221;\u00a0pageEncoding=&#8221;UTF-8&#8243;%&gt; \u5f88\u591a\u65f6\u5019\uff0c\u8981\u6c42\u8fd9\u4e2a\u8bed\u53e5\u653eJSP\u6587\u4ef6\u7684\u7b2c\u4e00\u884c.<\/p>\n<p><strong>2. JSP\u521d\u59cb\u5316\u8fd0\u884c\u65f6<\/strong> \u52a0\u5165\u5bf9\u8bed\u8a00\u73af\u5883\u53d8\u91cf\u7684\u6307\u5b9a\uff0c\u8c03\u7528\u8bbe\u7f6e\u8bed\u53e5 System.setProperty(&#8220;sun.jnu.encoding&#8221;, &#8220;UTF-8&#8221;); System.setProperty(&#8220;file.encoding&#8221;, &#8220;UTF-8&#8221;); request.setCharacterEncoding(\u201cUTF-8\u201d);<\/p>\n<p><strong>3. JSP\u5bf9\u8f93\u51fa\u5185\u5bb9\u505a\u5b57\u7b26\u7f16\u7801\u63a7\u5236<\/strong> response.setCharacterEncoding(&#8220;utf-8&#8221;); response.setContentType(&#8220;text\/html;charset=utf-8&#8221;);<\/p>\n<p><strong>4. \u8f93\u51fa\u5185\u5bb9\u7f16\u7801\u7684\u6307\u5b9a<\/strong> \u5982\u679c\u8f93\u51fa\u7684\u662fHTML\u6216\u8005XML\u9700\u8981\u5728\u76f8\u5e94\u7684\u6587\u6863\u91cc\u663e\u793a\u5730\u58f0\u660e\u5b57\u7b26\u7f16\u7801\u662fUTF-8, \u5982\u5728HTML\u4e2d &lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=utf-8&#8243;\/&gt; \u6216\u8005\u5728XML\u4e2d<\/p>\n<pre><code> &lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<\/code><\/pre>\n<p>\u7ecf\u8fc7\u4e0a\u8ff07\u4e2a\u6b65\u9aa4\u7684\u8bbe\u7f6e\uff0c\u57fa\u672c\u7684UTF-8\u73af\u5883\u5e94\u8be5\u5df2\u7ecf\u7edf\u4e00\u8d77\u6765\u4e86\u3002\u7136\u800c\uff0c\u5982\u679c\u5185\u5bb9\u6765\u81ea\u6570\u636e\u5e93\uff08\u4ee5MySQL\u4e3a\u4f8b\uff09\uff0c\u5b57\u7b26\u7f16\u7801\u4ecd\u7136\u662f\u4e2a\u4e0d\u5c0f\u7684\u95ee\u9898\u3002\u5982\u679c\u662f\u8fd9\u6837\uff0c\u9700\u8981\u5728JAVA\u8fde\u63a5\u6570\u636e\u5e93\u65f6\u548c\u8fdb\u884c\u8bfb\u5199\u65f6\u8fdb\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002\u5f53\u7136\u524d\u63d0\u662f\uff0c\u6570\u636e\u5e93\u53ca\u6570\u636e\u8868\u4e5f\u662fUTF-8\u7684\u7f16\u7801\u3002 \u57fa\u672c\u4e0a\u53ef\u4ee5\u786e\u5b9a\uff0c\u8bfb\u5199\u6570\u636e\u5e93\uff0c\u5982\u679c\u4e0d\u8fdb\u884c\u5b57\u7b26\u8f6c\u7801\u4e14\u64cd\u4f5c\u6b63\u5e38\uff0c\u9700\u8981\u5728\u5982\u4e0b\u56db\u4e2a\u65b9\u9762\u53d6\u5f97\u9ad8\u5ea6\u5730\u4e00\u81f4\u3002 Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8 \u5bf9\u5e94\u5730\u5728JSP\u4e2d\u8fdb\u884c\u8865\u6551\u7684\u76f8\u5e94\u63aa\u65bd\u5305\u62ec:<\/p>\n<p><strong>5. \u00a0\u8fde\u63a5\u6570\u636e\u5e93\u65f6<\/strong> \u5728JDBC\u7b49\u9a71\u52a8\u52a0\u8f7d\u65f6\uff0c\u589e\u52a0\u5b57\u7b26\u7f16\u7801\u6307\u5b9a\u53c2\u6570 setCharacterEncoding=utf8 \u5728\u8fdb\u884c\u521b\u5efa\u8fde\u63a5\u8fdb\u884c\u67e5\u8be2\u65f6\uff0c\u9996\u5148\u6267\u884cSQL\u8bed\u53e5 set names \u2018utf8\u2019 \u7ecf\u6b646\u4e2a\u65b9\u9762\u7684\u8bbe\u7f6e\uff0c\u5927\u81f4\u6210\u4e86\u3002<\/p>\n<p>-GWA2 \u662f\u00a0General Web Application Architecture\uff0c\u00a0\u901a\u7528\u7f51\u7edc\u5e94\u7528\uff08\u8f6f\u4ef6\u7a0b\u5e8f\uff09\u67b6\u6784\uff0c\u4e5f\u63d0\u4f9b\u4e86 <a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-php\" target=\"_blank\">-PHP<\/a> \u5bf9\u5e94\u7684\u7248\u672c\u3002 <a href=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/07\/utf8.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-1290\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/07\/utf8.png\" alt=\"utf8\" width=\"933\" height=\"247\" srcset=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/07\/utf8.png 933w, https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/07\/utf8-300x79.png 300w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/a> \u00a0 \u9644\u8bb0\u53ca\u6269\u5c55:<\/p>\n<h1><a href=\"http:\/\/kunststube.net\/encoding\/\" target=\"_blank\">What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text<\/a>\u00a0\/\u00a0\u6bcf\u4e2a\u7a0b\u5e8f\u5458\u90fd\u9700\u8981\u7edd\u5bf9\u3001\u79ef\u6781\u5730\u77e5\u9053\u4e00\u4e9b\u6587\u672c\u7f16\u7801\u548c\u5b57\u7b26\u96c6\u7684\u4e8b\u60c5<\/h1>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u95ee\u9898\u57df\u88ab\u5b9a\u4e49\u4e3a -GWA2 \uff08-\u5409\u5a03\u5154\uff09\u7684 -Java \u7248\u672c\u7684\u591a\u8bed\u8a00\u7684\u7f16\u7801\/ &hellip; <a href=\"https:\/\/ufqi.com\/blog\/gwa2-java-i18n\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,7,6,2],"tags":[86,146,148,147,149,150,55],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1289"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=1289"}],"version-history":[{"count":17,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1289\/revisions"}],"predecessor-version":[{"id":1701,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1289\/revisions\/1701"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}