{"id":104,"date":"2008-09-18T23:34:50","date_gmt":"2008-09-18T15:34:50","guid":{"rendered":"http:\/\/amjet.dyndns.biz\/blog\/IT\/?p=104"},"modified":"2015-11-23T20:06:58","modified_gmt":"2015-11-23T12:06:58","slug":"form-submit-%e4%b8%ad%e6%96%87%e4%ba%82%e7%a2%bc%e5%95%8f%e9%a1%8c","status":"publish","type":"post","link":"https:\/\/blog.amjet.biz\/IT\/?p=104","title":{"rendered":"java form submit \u4e2d\u6587\u4e82\u78bc\u554f\u984c"},"content":{"rendered":"<p>\u9019\u500b\u554f\u984c\u9678\u7e8c\u9047\u5230\u5e7e\u6b21\u4e86\uff0c\u59cb\u7d42\u77e5\u5176\u7136\u800c\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\u3002\u9019\u662f\u6700\u8fd1\u4e00\u6b21\u7684\u8655\u7406\u6848\u4f8b\uff1a<\/p>\n<p><strong>\u74b0\u5883<\/strong><\/p>\n<p>OS: CentOS 5.2 (utf-8)<\/p>\n<p>Database: MySQL 5 (utf-8)<\/p>\n<p>Application server: Tomcat 6<\/p>\n<p><strong>\u7db2\u9801<\/strong><\/p>\n<p>&lt;input type=text name=keyword&gt;<\/p>\n<p><strong>\u7a0b\u5f0f<\/strong><\/p>\n<p>String keyword=request.getParameter(&#8220;keyword&#8221;);<\/p>\n<p>\u7db2\u9801\u7684 input \u8f38\u5165\u4e2d\u6587 submit \u5f8c\u7531\u4ee5\u4e0a\u7a0b\u5f0f\u78bc\u63a5\u53d6\uff0c\u539f\u672c\u7684\u4e2d\u6587\u90fd\u8b8a\u6210\u4e82\u78bc\u3002\u89e3\u6c7a\u7684\u65b9\u6cd5\u662f\u6539\u7528\u4ee5\u4e0b\u7684\u63a5\u53d6\u7a0b\u5f0f\u78bc\uff0c\u5c07\u6536\u5230\u7684\u5b57\u4e32\u91cd\u65b0\u7de8\u78bc\u3002<\/p>\n<p>String keyword=new String(request.getParameter(&#8220;keyword&#8221;).getBytes(&#8220;iso8859-1&#8243;),&#8221;utf-8&#8221;);<\/p>\n<p><strong>Why<\/strong><\/p>\n<p>Tomcat \u5728\u8655\u7406 GET\u3001POST \u53c3\u6578\u6642\u9810\u8a2d\u662f\u63a1\u7528 ISO-8859-1 \u7de8\u78bc\uff0c\u8acb\u53c3\u8003\u6b64 <a href=\"http:\/\/tomcat.apache.org\/tomcat-5.5-doc\/config\/http.html\" target=\"_blank\">\u7db2\u5740<\/a> URIEncoding \u90e8\u4efd\u7684\u8aaa\u660e\uff0c\u6240\u4ee5\u7b2c2 \u6bb5\u7a0b\u5f0f\u624d\u6703 work\uff0c\u8acb\u96a8\u8457\u60a8\u7684\u4f5c\u696d\u7cfb\u7d71\u53ca\u8cc7\u6599\u5eab\u7de8\u78bc\u8a2d\u5b9a\uff0c\u8abf\u6574\u63a5\u53d6\u53c3\u6578\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n<p><strong>Browser<\/strong><\/p>\n<p>\u4ee5\u4e0a\u7684\u4f8b\u5b50\u662f\u9001\u4e00\u500b keyword \u5230 tomcat web application \u67e5\u8a62\u8cc7\u6599\uff0c\u5f8c\u4f86\u51fa\u73fe\u53e6\u4e00\u500b\u554f\u984c\uff0c\u5f9e Firefox \u9001\u51fa\u4e2d\u6587\u7684 keyword \u53ef\u4ee5\u6b63\u78ba\u7684\u67e5\u5230\u8cc7\u6599\uff0cExplorer \u537b\u67e5\u4e0d\u5230\uff0c\u7d93\u904e\u6e2c\u8a66\u548c\u67e5\u8a62\u76f8\u95dc\u8cc7\u6599\u5f8c\u767c\u73fe\uff0c\u5f9e Explorer \u9001\u51fa keyword \u524d\u8981\u7528 javascript <a href=\"http:\/\/www.w3schools.com\/jsref\/jsref_encodeURIComponent.asp\" target=\"_blank\">encodeURIComponent()<\/a> \u7de8\u78bc\u5f8c\u518d\u9001\u51fa\u624d\u6703\u6b63\u5e38\u67e5\u5230\u8cc7\u6599\u3002<\/p>\n<p><strong>2008.11.27 \u52a0\u8a3b<\/strong><\/p>\n<p>\u4e0a\u9762\u60c5\u5f62\u662f\u767c\u751f\u5728\u672a\u6307\u5b9a form \u7684 method\uff0c\u6839\u64da\u898f\u683c\u9810\u8a2d\u6703\u4ee5 get \u50b3\u9001\u8cc7\u6599\uff0cTomcat \u7684\u6587\u4ef6\u4e5f\u6c92\u6709\u8aaa\u660e URIEncoding \u662f\u6703\u91dd\u5c0d get \u6216 post method \u4f5c\u8655\u7406\u3002\u4eca\u5929\u53c8\u9047\u5230 form submit \u4e2d\u6587\u4e82\u78bc\u554f\u984c\uff0c\u9019\u6b21\u4e5f\u4e0d\u7528\u91cd\u65b0\u7de8\u78bc\u53c3\u6578\u4e86\uff0c\u76f4\u63a5\u628a form method \u8a2d\u5b9a post\uff0c\u554f\u984c\u5c31\u89e3\u6c7a\u4e86\u3002\u770b\u4f86 submit \u7684 form \u6709\u4e2d\u6587\u6642\uff0c\u7528 post method \u6703\u662f\u6bd4\u8f03\u597d\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5404\u7a2e Application Server URI encoding \u7684\u8a2d\u5b9a\u5728\u9019\u500b <a href=\"http:\/\/docs.cksource.com\/CKFinder_2.x\/Developers_Guide\/Java\/Configuration\/URI_Encoding\">\u7db2\u5740<\/a> \u6709\u5b8c\u6574\u8aaa\u660e\u3002<\/p>\n<p><strong>[ratings]<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9019\u500b\u554f\u984c\u9678\u7e8c\u9047\u5230\u5e7e\u6b21\u4e86\uff0c\u59cb\u7d42\u77e5\u5176\u7136\u800c\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\u3002\u9019\u662f\u6700\u8fd1\u4e00\u6b21\u7684\u8655\u7406\u6848\u4f8b\uff1a \u74b0\u5883 OS: CentOS 5.2 (utf-8) Database: MySQL 5 (utf-8) Application server: Tomcat 6 \u7db2\u9801 &lt;input type=text name=keyword&gt; \u7a0b\u5f0f String keyword=request.getParameter(&#8220;keyword&#8221;); \u7db2\u9801\u7684 input \u8f38\u5165\u4e2d\u6587 submit \u5f8c\u7531\u4ee5\u4e0a\u7a0b\u5f0f\u78bc\u63a5\u53d6\uff0c\u539f\u672c\u7684\u4e2d\u6587\u90fd\u8b8a\u6210\u4e82\u78bc\u3002\u89e3\u6c7a\u7684\u65b9\u6cd5\u662f\u6539\u7528\u4ee5\u4e0b\u7684\u63a5\u53d6\u7a0b\u5f0f\u78bc\uff0c\u5c07\u6536\u5230\u7684\u5b57\u4e32\u91cd\u65b0\u7de8\u78bc\u3002 String keyword=new String(request.getParameter(&#8220;keyword&#8221;).getBytes(&#8220;iso8859-1&#8243;),&#8221;utf-8&#8221;); Why Tomcat \u5728\u8655\u7406 GET\u3001POST \u53c3\u6578\u6642\u9810\u8a2d\u662f\u63a1\u7528 ISO-8859-1 \u7de8\u78bc\uff0c\u8acb\u53c3\u8003\u6b64 \u7db2\u5740 URIEncoding \u90e8\u4efd\u7684\u8aaa\u660e\uff0c\u6240\u4ee5\u7b2c2 \u6bb5\u7a0b\u5f0f\u624d\u6703 work\uff0c\u8acb\u96a8\u8457\u60a8\u7684\u4f5c\u696d\u7cfb\u7d71\u53ca\u8cc7\u6599\u5eab\u7de8\u78bc\u8a2d\u5b9a\uff0c\u8abf\u6574\u63a5\u53d6\u53c3\u6578\u7684\u7a0b\u5f0f\u78bc\u3002 Browser \u4ee5\u4e0a\u7684\u4f8b\u5b50\u662f\u9001\u4e00\u500b keyword \u5230 tomcat web application \u67e5\u8a62\u8cc7\u6599\uff0c\u5f8c\u4f86\u51fa\u73fe\u53e6\u4e00\u500b\u554f\u984c\uff0c\u5f9e Firefox \u9001\u51fa\u4e2d\u6587\u7684 keyword \u53ef\u4ee5\u6b63\u78ba\u7684\u67e5\u5230\u8cc7\u6599\uff0cExplorer \u537b\u67e5\u4e0d\u5230\uff0c\u7d93\u904e\u6e2c\u8a66\u548c\u67e5\u8a62\u76f8\u95dc\u8cc7\u6599\u5f8c\u767c\u73fe\uff0c\u5f9e Explorer [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[56,133,57],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-java","tag-form","tag-java","tag-57"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=104"}],"version-history":[{"count":11,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":1042,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=\/wp\/v2\/posts\/104\/revisions\/1042"}],"wp:attachment":[{"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amjet.biz\/IT\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}