jsp/servlet中的编码问题

时间:2020-12-22 03:17:20

首先声明以下只是我个人的看法,有部分观点与网上人云亦云的观点不一样,不过凡事必恭亲,我还是相信自己测试的结果

推荐一个很好地URL编码详解http://www.ruanyifeng.com/blog/2010/02/url_encoding.html

与网上的共识是

JSP中

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

二者里面的contentType="text/html; charset=UTF-8"作用是一样的,只不过后者优先级高于前者
相当于resposne.setContentType("text/html;charset=utf-8")作用是指定HTTP响应的编码,同时指定了浏览器显示的编码
即服务器将页面以utf-8传输到浏览器,浏览器再以utf-8显示 pageEncoding="UTF-8" 指定的jsp页面本身的编码为utf-8,同时在被服务器转换为.java文件时采用utf-8编码(默认使用iso-8859-1),
但是.java文件编译为.class文件统一使用utf-8编码(JVM规定如此)
pageEncoding指定的编码一定要与JSP保存的编码一致
可以在window-preference-web-jsp Files修改jsp默认保存编码(已保存的JSP编码无法修改,只能右击修改) 最好将contentType和pageEncoding指定的编码一致 以下关于JSP页面的不同提交方式使用的编码是我与网上一些观点的不同
向服务器提交数据的方式有get和post 以下是测试
<body>
<form action="/webExer/LoginServlet" method="post">
登录:<input type="text"><br> 验证码:<input type="text"
name="imageCode">
<!-- <img src="/webExer/ImageCodeServlet"><br> -->
<input type="submit" value="提交">
</form>
<input type="button" value="get跳转" onclick="jump()">
<script type="text/javascript">
function jump() {
window.location.href = "/webExer/LoginServlet?imageCode=get提交";
}
</script>
</body>

public class LoginServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//request.setCharacterEncoding("UTF-8");
//response.setContentType("text/html;charset=utf-8");
String imageCode=request.getParameter("imageCode");
String x = new String(imageCode.getBytes("ISO-8859-1"),"UTF-8");
     String xx=new String(imageCode.getBytes("ISO-8859-1"),"GBK");
     //原生数据
System.out.println(imageCode);
     //转码后数据
System.out.println(x);
System.out.println(xx);
PrintWriter out=response.getWriter();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}

当访问JSP时

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATUAAABfCAIAAAAGZcfbAAAM4ElEQVR4nO2d328TRx7A5785BC/YIRa2Kh76cCDK4zWJAaVcsVdH+5IXX0TcHEakECLiGCFRBZL0gJMuPXI6Jb6sSAmpAPFAVYF6bVMXhxKcNA2JKSF2nMReu/ewv2b2x+xm7SQe5/vRV+p6dmZ2nfrDd3a8O0bJhXUICIjqDLTtZwABAWEW4CcERPUG+tf4UwgIiOoM9DsAANUK+AkA1Qv4CQDVC/gJANUL+AkA1Qv4CQDVC/gJANUL+AkA1Qv4CQDVCzN+vphO3b334Pa/4xBsxd17D15Mp7b748MqzPiZmll4lV7a7rMANsyr9FLyxdx2nwWrsOTndp8C4BDw0zEb9TMZ8yFfLKm8ULY3G/CTXcBPx1D85DmkheMVQZMxH0K+GJ/E/UzGfLo2uh6cAX6yC/jpGLv5MxnzyXJJ3sqZk+eQzSSajPnAz50I+OkYev6UbSJGtfgrniNzomUCBT93IOCnY8z9TCZ5cQib5DmdVzyHfD4flkXtYJk/pTGzYY/gJ7uAn46xGt/KCVJ7McrFiJRq59ITx1hC8LM2AT8dQ/NTO3jdeIWyrjhJwE92AT8dY+YnMU1LzYM8p+ZD7VwRNqukFjgTFvxkF/DTMVbjW5pQupnbZDIp+iwXG7zSfiVjF/CTXcBPx1TUT2yH2CYZ8yEuFvNxvGhqGWNd8JNdwE/H2PFzw/M8ckMuJtpNm/exC/jJLuCnY+zcn2B0Gx/25agWaaqX4/Hsm9RM95odCOZvaxDw0zG27h/STfPwHEI+jk8aVCMEI785xWeSzI8DftYc4Kdj7N7fh19rGtyvIClLTAsZD4CdXoiCn+wCfjrG1E+Du+MpVOhLTgrgJ7uAn46B5z+BTQf8dAz4CWw64KdjWPIT1jdhEVjfpByY8TObXZ159QaCxchmV7f748MqzPgJADsQ8BNghitXrrS2tr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ASeS+dHUjcm52gJ8A61j4uZArDk2tUiLcpAxkT4apNbc+FnLgJ8A2Fn6+yhW/SOYYjVfgJ8A41PWHzo58N7c8tVT4508rzMXUUuG7ueUDZ2H9IYBhaH4e7x4JXH/4/a+Z+RWBufj+10zg+sPj3eAnwDAW69/6Lw0fiIxs+2K2DuJAZMQPi2sCjAPrxwNA9QJ+AkD1An4CQPUCfgJA9QJ+AkD1An4CQPUCfgJA9fJ/sorxHTM+TsAAAAAASUVORK5CYII=" alt="" />

POST方式

点击post提交按钮时form表单以post向后台传数据,并在控制台打印获得的数据

指定为UTF-8编码

<%@ page language="java" contentType="text/html; charset=UTF-8"

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI4AAABLCAIAAAApuihYAAAEb0lEQVR4nO1by7XcIAylLgqiHkpIFTTjVTapICer5JGFbRBCfPxmPCCse97Cg0EWur6CIEf9/PUn/Hnvf//5u+Tfv6+vry/P+k89hCrPH5gqwbQQqthAqGIDoYoNhCo2EKpmhjPKuPMHTZUzCiMOmQOb1TXXwgy03cjxcYqzzQyggyqy6/3YrO58njMhxJvVmA/QBDrSw/1m9XCyShNfhKpAD7zOzVA2N6tLYhuDW6iCqTHcckZp646MZFzsBQISBx6NOIMBy0kcE9WEH+cFoSnkdcakL2mNcPIIojNKKW0M5UlrVPZO9E4czcRdosoZaC3OF/i0P3dvju9KOnC/Z4AqsgHYC0AvSFz0WoOsUFSF+KDZJUQYF55ydiM86RiFvOufeIy/M0pdoQpPmnSXuqajle8MKh4HKQXX4RucWm+rKnUARAMCPZL2pGvUKxOPAX6RqiCli1RtVqtcKsUZ7gbiEpMaxOaT383173y3aUrx8LonpVHfnfi3qcoTIOEveQ3XBmfthlXRospvVmtjNKmk03hsBHbIUCabPtJJ70zBJeRJ5ygYwgsT/3YCDGPIbUWNKqj56NyRMYwJfh6thfcU+gJyCLVrx48jzWU9iH+r5UHEnvSNInp3TPzCtkIwEYQqNhCq2ECoYgOaqh+C+SCqYgOhig2EKjYQqthAqGIDoYoNpqUqP4Q9EA7R5irk3o/PUfWeTxg2q7U9DUayEj5LNV7mqFFltVJKW5vVo+Nd4vQ6tmt9hBWeY6cDYiU3KfNVy/cUVRV/lkFDVUnhGRzt47f4DB/8wGSvbgFTxJdDLlZEziLkUaBxLg6kaw55ORFcLpgb21ShMB3rRxp2ZxKCCmrLqCI+NzzZTYXYlolQhZJMB1VJa1VVsW6WfeyFS+49GU0SIJ3E0tg6Q64faQ053jqX/WANF03BgpQXXUk8fVvhvd8/JCBW+EKCSvcPWHq4vZwAgfnDgQVjfxHXEqBgIJqbdbDUC4Zi2tMKAYZQxQZTUKWU+tgovpiOqnxL2DlwecxIVeVWDz7n92cxmKo8ys8J/VVwUlWl8QmMzkhVXVUlVpZna4rSYkh9TSNP3mUMLi0eTpQXqk5hrU3SjrGlRV8iw18R0BN48oNLi8EJKu5NAvrT5hoYWFoEThSoam7Wn8OTH1tajE6IqjowtLQYnEjpaXKA1NYU3xoYXFqEWS6PPsqB9ZTYkzBZQ0qLbDDFaYWgB0IVG0xBVX0HiJafS6vRSkvXXFQ1efLV3QfZuY5b5nMPxlNFbtD7qSrdIseyxvjSIrruSYD59j1XSaUPOz3tmEJVnbEj9fccjKfKdy8/uezqcil1EFU1cPW4tnSrlBgrjXWzXDC4tJi/6c3X/3VV+fWo8veXFg8nrnwGc1VVpPE1qbq1tAjf8berKu+TG2GE8aVFFMc7VJWTtCRVHyotwlXkLaoilYRo5kXY4NIiyUe/bpoShE/Jja9G1Yf/1+IbE2CPLl/09pOQ0iIbTHFaIeiBUMUGQhUb/Ac6WesR1fGzRgAAAABJRU5ErkJggg==" alt="" />

后台中可以发现原生数据是乱码,但是IS0-8859-1转UTF-8后数据正常显示发现post提交过来的是ISO-8859-1编码

那为什么IS0-8859-1转GBK是乱码呢?因为JSP页面是UTF-8,浏览器用的UTF-8编码显示JSP页面,

post提交时默认采用当前浏览器使用的编码即UTF-8提交,但是服务器有自己的编码,在POST提交方式下,注意我说的是在POST提交方式下,跟GET无关,tomcat默认的编码是ISO-8859-1(在server.xml里修改对该默认编码无效,下面会进行测试),于是tomcat又用IS0-8859-1重新编码了一次,也就是传到servlet里的数据经过了两次编码,先UTF-8,在ISO-8859-1,所以拿到IS0-8859-1解码的字节后转GBK当然会乱码了。(网上大都说get方式是先采用浏览器面默认编码,在由服务器用IS08859-1进行二次编码,但我测试的是post方式这样做的,get方式不是,get方式会在下面介绍,强烈建议自己动手试试)

解决办法一般用request.setCharacterEncoding("UTF-8");但是该方式只能用于post方式

request.setCharacterEncoding("UTF-8");

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ0AAABRCAIAAABHbjNOAAAD+klEQVR4nO2cQbLbIAyGORcH4jwcoadg9Y6QmR7AM53ppssuu3UXtrEkhCF2XkKU/5ssHGywxG/JJHLi5oLff/7l1+12+/nrr8lX+rqVvpvBlU3Q1QBtXdOX2dfzp/tptHV9vk3gOtDVJtDVJtDVJtDVJtD1vUjBhdRxXK+uKThJ1/hPZIr+yLTsgY+T2n93cTTPCI/W9d5xH8QUfef5Ush6TNFL8UgTOVDvPk/Rv1zZmuOfqGvWkm6Xw2hjTtHXwvg1vF5XmqHzrhScj2lNjCHtR5HZ2zuujTKRkpHZpLN4zG+2DSVahdWF7HMtihUj1xlPwTnnQ9AsafUqLqBex4Un6sxv7aUr9+iaAj31PjnEgeXsS/N+FfKOy75A4q3oIK0g1wLJn/r9UYyi6ZpnSXjHVAspn2U7TLGko5ewrt/xff6PZt7H6ZqucoZU37RtfWrLpc+BezlIsz80Nvjo7XjlBpCLkyJOqVvS1euK48UE0+O39ofrmoP0Tl2n6F0ZhNXpWAbYb4t8QDk8e9+8Z28Xv66/7H5sSa3XWccPdGUT++g8rDinbtP7WYpxkvHW0nWeovcheNqHnsWFRBvJOOq8syWwauScQsUkYUlnLzqFdzhez8N8uf+d66YjXWnq2T1ZE1cI2am1tRIB1BaSyrQPPPJ06nDFEcpn4nLGpSV9vZSjOxzvWDctPcvz4PsmA0BXm0BXm0BXm/Tq+gO8FYhXmwyqq7pQ/6ZeJnkDXV1BZ8dP5j10PdjVw/PsHobhdC0lgU4nGE7Xhc54PWj8cPnfQ9fjeK1J+MnSvlLXg8eIcgZuDoJllMp9ukbvnPMxFo957HsXmGB7u/fex3nm1ZOywxajc31lJN1AHubcHa/seQ5SfWLPKKTgFv34E2FLzZAMpcTrweKoPzQ/XNT5nK6i1LhWsLlGKTA1K3HcyMNiu6lWf/Y2zwld5fMXLV1ZazNeV7MqujY/50DUhVN5WNOG653Cdgxr509b7LuKpzwRrxc5E68h7Ise/jiYknD5AkkGdWXZJLVsCibiuBnW5rmahx9vEEm2pVQiFR9n5p68bZUTn3PWOH2WheAMg37fBC4CXW0CXW0CXW0CXW0CXW0CXW0yoq7kh0ixpx2UjFdXJ7UB9pPGWjvQGLSuvlL7Z5YR/rFlbIarq1Nq/9Iy3L+3jMegdfW1U3kfrbUDzqB19Ur/ejvgDFpXBxcZs66+ZVsZmbV2IBmurg4eAurqNhnx+yZwHehqE+hqE+hqE+hqE+hqE+hqkxF1RV39Oqir2wR1dZugrm4T1NVtgrq6TVBXtwnq6jZBXd0mqKvbZMTvm8B1oKtNoKtNoKtNoKtNoKtNoKtNoKtN/gNs3xV2vpQZ0gAAAABJRU5ErkJggg==" alt="" />

这是在控制台显示,如果要在浏览器中正常显示别忘了加上response.setContentType("text/html;charset=utf-8");

为了证明自己的测试结果,我把contentType设置为"text/html; charset=GBK"试试

contentType="text/html; charset=GBK"
String imageCode=request.getParameter("imageCode");
String y=new String(imageCode.getBytes("UTF-8"));
String yy=new String(imageCode.getBytes("GBK"));
String x = new String(imageCode.getBytes("ISO-8859-1"),"UTF-8");
String xx=new String(imageCode.getBytes("ISO-8859-1"),"GBK");
System.out.println(imageCode);
System.out.println(y);
System.out.println(yy);
System.out.println(x);
System.out.println(xx);

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMUAAABkCAIAAAC5GmPsAAAE9UlEQVR4nO2dS7KbM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VY1Ucbnz6dTyf5JMWGoWHNanUkU/ZcnxNo8s56Zz+I6uK6KI/ypNZNpB76h26WSM6BhPJ+wTMufX14cDG83B+He4BPYAk+gSX4BJbgE1iCT2DJJXziXU6XwYtPvJ/uHvjIp+P9dHfBSz7dAe+nuzJe8ul2eD/dpfGST3c04v10V8ZLPl2rPe+nux5e8uka8H66C+Iln473090DF/l0cBvIpwNLvNwfh3uAT2AJPoEl+ASW4BNYgk9gCT6BJV58Ij/uHvjOpyM/7mr4zqfTlIMnfOfTKcrBFb7z6frl4A/P+XSjcvCH43w6uCCu8+m65eAR8unAEvLpwBIv98fhHuATWOLIp+mt1+i+1wo+hFOfpgplQ/hZ/PrU2aXhe+OGBBc+1Srgx0Vx4dNzKLr41ClEux/Hr0/9+CSpg1I/i498usdQ1L8WjMtztzjKp+tcPClDFCb9OC7y6ToX3fpQhEwecJRP15RjaIl+lYQv4CifTvJpeL8AmfzgKJ+O+HQD/OTTDX6FcGPoedwahjH4Ai7y6dJFrVakWPL6K6BmfYTPQT4dWOLo/jjcAHwCS/AJLMEnsASfwBJ8AkvwCSzBJ7DkH9forBnT4IqOAAAAAElFTkSuQmCC" alt="" />

可以看到只有 String xx=new String(imageCode.getBytes("ISO-8859-1"),"GBK");没有乱码,证明我的想法是对的

再证明修改server.xml对POST方式默认编码无效

在servler.xml中指定任意编码

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYMAAAA8CAIAAAAL7UFRAAAIsklEQVR4nO2dv2/iSBTH5+9JfUI6N/kPUqVfIUWu06Y4mSYSpSksqq2Q0gynFKvQZo0i5bRaiQqncLGbZoWWDl2xFXOFPb88Mway4PHF349eAY/xzPPAfHnz7BDy69cv1nJ+fL/68Hj+13ffcQAATgVpUIl+3n54PNds+VTn13j99OX8w+PVp3+bihYA0BxNKtHbef30BTkRAO+Y1isRtmYAdIA2K1Gxa/ty98N3IACAE9NmJQIAdAUoEQDAP1AiAIB/oEQAAP9AiQAA/oESAQD8AyUCAPgHS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7INxKhtIEZtAzFqGxpnFL5ACutqzUplggwGjMIdKncI5bJTMmVmorZtZPQ2woxRroKeVch1dCqVCWo0zmilGueWEnRMGDOKLo8pdhWU8aHOVNlfgibGYhSVy87qX0fRvwRN1F91jRjlFNCEhnVadWujWUZrCwm1MSVGjVZdytFxMBajMOI610VVP+j2woRQ5w4DO+TOoof1GBU9EDRRJ0d1zqrpl5mLfzXNCQwNMqpvm1ZxSYzqYwKMqnc6CkPRieiTuDSFAaOEmQAxahuIUdugy6jsJ7/RrQCFQu3rJV1oORgwalpH6Zf2Q++eEXpWoe8gmspRNUNi3KG+2DRalw6JGM1glKNqFlOMIQVnzKfoHOVeDcMI2IZp5GgqsChqQjrFptFD9QRyFg3mKKcjHkIreKhOO2V+8soOfu/d4M5IFOI9aO4+n5Pfe0/jOqqTTOgMEIWVCSp6zuHM995T+vWimamoQ9FW5k3Ryhv3f0Aaw5T2upVpJGYhq6OdMchOx773rsMoJ1GkF2qo6U1ma2zi2PfexowqkmOCjHIOOX2xUbEDzqJmjqIRnBSjiuznznItYm059713zRxVy2XKqEQ0EfU1p4XCvzvQZZQwKyBGbQMxahuIUdtAjNoGYtQ2EKO24X/vqsaOEktnxAAAAABJRU5ErkJggg==" alt="" />

与前面GBK编码测试结果一样,说明server.xml指定的编码对POST方式无效,再次证明了我的想法

GET方式

先测试UTF-8(此时server.xml里未指定编码)

GET方式就是在URL后面拼接参数,我在JS里传了一个死参数

<input type="button" value="get跳转" onclick="jump()">
<script type="text/javascript">
function jump() {
window.location.href = "/webExer/LoginServlet?imageCode=get提交";
}
</script>

servlet中

     String imageCode=request.getParameter("imageCode");
        String y=new String(imageCode.getBytes("UTF-8"));
        String yy=new String(imageCode.getBytes("GBK"));
        String x = new String(imageCode.getBytes("ISO-8859-1"),"UTF-8");
        String xx=new String(imageCode.getBytes("ISO-8859-1"),"GBK");
        System.out.println(imageCode);
        System.out.println(y);
        System.out.println(yy);
        System.out.println(x);
        System.out.println(xx);

控制台打印

aaarticlea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5AkMyBMYkCcwIE9gIpqMBXk8RDQZC/J4iGgyFuTxENFkLMjjIaLJWJDHQ0STsSCPh4gmY0EeDxFNxoI8HiKajAV5PEQ0GQvyeIDLYwID8gQmovIAHkCewIA8gQF5AgPyBAbkCQzIExiQJzAgT2BAnsCAPIEBeQID8gQG5AnM9wFjjny060QYAAAAAElFTkSuQmCC" alt="" />

可以看到jsp传过来的参数直接获取就能正常显示

即String y=new String(imageCode.getBytes("UTF-8"))能正常显示,即传过来的数据是UTF-8编码

也就是说get方式传到后台的数据是UTF-8,那么这个UTF-8编码是不是浏览器当前默认编码呢?

我用GBK试了一下

contentType="text/html; charset=GBK

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGEAAABZCAIAAAChTd00AAACBUlEQVR4nO2Yy3HDIBRFVRcFUQ8lpApV4Q5YZZMSsiULOQIsKdcz4SOkc8aLzLPDPI4AmzuFED6/vtfX4/EIkDMFHClwpMGR5tDRB/zCOtLgSIMjDY40ONLgSNPIkXdm2mCcL1Wv0fNKFUfO2Dmv+G1ptsuci9T/3/MfvONotusDczY+t/SZGvf87OZBL1O6uCNnnvNc5r825EzszTsTNd1uHXlnksn7VczOwRCbv7WjpKHZpvWcmznK95Qzca/N9vALJf7LbJf1dXFH6bYyxqQN5fstaX495bOj7B7f/d6Z2g2dkLccJQvp8Ay6MNxFNDjS4EiDIw2ONDjS4EhDxqYhY9OQsWnI2DRkbBoyNg0Zm4aMrYijBDI2MrZ9uItocKTBkQZHGhxpcKTBkaapo/grOf+dVapeiUYZWwjPC17ypy9cr0ajjO2Vnbtp0XpRGmVsLxzd+0rVy9IoY4ssi3J7jpSqV6BRxrY3Qp16BRplbEPTKGPL39i6LVWvAhmbhoxNw11EgyMNjjQ40uBIgyMNjjRkbBoyNg0Zm4aMTUPGpiFj05CxacjYNGRsGjI2DXcRDY40F3E0TVPFwQOO5OABR3LwgCM5eMCRHDxcImMbz1H7jK27owEyts6OhsjYujoaJGM7kaPTZmzd99oAGVvvM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xzstuZQPbr+tq0pUNjX4Sd9UGIIGaWQASgARyQAASgARyQAASgARyQAASgARyQAASgARyQAASgARyQAASgARyQAASgARyQAASgARyQACSCyBBFCH/CUByByTXoghZ6LPZzUev58TWaZepq8ZYPyBDAFKDQDLSqnRHVGAdxuY6e5CiPCK3cNjyUFOsHxAmAMl7kJYZRahWkKoKIGQppnKsHxAuAMkdkMqPkZYVRahGkGrqkNUQ6wdECEByByQXowiR9DFCVJEVLB8kdqwfECEAqcEg1R5FyCmPtLxYPyBSAFIjQaorihATJEsiMayptunXEusHRAhAahhIqM4oQuwt52SkICL4Nx1UyHbWrqZYPyBCAJI7IFWabKg7ipDlDkvQVWYZ+DUWCHXE+gHhApDcAak9owg1xUM0p0yQptpabbDWzsteFdOfwsqGMjJBKrW12gAkUDMLunYAEsgBmSCdiCttbAASyFWZIClKoY0NQAK5KhOkbE5uYwOQQK7KBCmzKLexAUggV4VNNizKbWwAEshVYSBl5TY2AAnkqkyQ0lm5jQ1AArkqE6RUVm5jA5BArsoEKZmRW9q6urrKXG0USLYL7CCKUHvJBGkhI7e0dXV1dXV12V31ECT6XFU2I9VFEVLX1+HnxsKCt+YUBpIkt7R16WJebZBHqrTroHwUIQw2jB9Ygt2MakOQmCx5CZLtdiSNkmqjCOEUEo4INgU1n0yQ5iW5pc2giHm1IR6pTIOvIoqQTRwfCXxSM8oEaS4tt7SpFNld9Qykcu7IYKQqFggMyaERuKSmkwnSbFpuaevq6ipz1WOPZEZQUPttlk15laMIkaiRIIFLajqZIM2k5DY2jz0SJ4ha/JEozwkCjxDiOHPqraooQuCRWkkAksMgGYryCCFOEHiO5zlyNk6qKooQPb9QIbIdqKEyQZpOyW1sXoKkvkgyQqBiM9gmTdVEEbLmMcOqAkdNJhOk20m5ja0Bs3Z68y/f5stFEWIPhWCA1IwyQPp/1cq7tCNS+tAAAAAASUVORK5CYII=" alt="" />

注意到一个细节

使用contentType="text/html; charset=UTF-8”时浏览器URL参数显示为中文

aaarticlea/png;base64,i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lbzGpnn2nOVhyo3vvRZ1t3H3ryub/Ip3f4YrRe6W+Y0P8eKr/fMG2QhbeM8hWh1M7lYVBJtF15kMiykbWxD+5ZkZ6LdpRqsbUYK7gLXGBR13pGb1jHs66z3FzipObcznc/3rb38Bc1dfKJb1jHLYp/W15XV1dXV1d+vy1XF/WejhLlEiE5lIs4fIuikmh7SQSZX1Fjc5GzjR2Tnugcl5LHxSXOXfievmxwh+WSTXqitL4jGlvKe6yl5WXlLd4WptjhFFQl0faSCDK/opzBpLF/XN9xe24+lRX0D7Xl0+jbb1nhfzGCQKDCinIGk/d8cZ2x32SzK7EzeUw2u6Hz5vKy3FYRBAKB8i7KEUw6gsm7c5Fv9N39Y3Oz86l10zMyrTWYY4v5312CQCCQvChHMIEYcga+amgzDdhn55ProNU28cmZy181tNVd6wUAACgwP3mZI5gYmZmnm7qvtN20eyLKXczuiTSYbn77vXncFZ6+nwQAACg81FQgQTLpW2J6Rk9faDGY70x6ojP3kzLY3ZHm7junL7Rc67k76VviFQUAAFAw+F6GGJnh9F3DX15oqTVYWm322/d8k57oj8G4Mxgfn+Nusb5Wm73WYPnyQou+a3hkhit6MwAAeMgR9zLEpHfRMjLT2DFU22w5c8l0Sms8pTWeuWSqbbY0dgxZRmYmvYtFbwAAAMBUIEHdCyQAAABKHeqePwEAAFDqUKw/AQAAUOqAlwEAUA6AlwEAUA6UoZd1DE7UX71Ro9WXE/VXb3QMThS9bwFgw1JuXtY+MN50vcsbisQSy+WENxRput7VPjBe9B4GgI1JuXlZ3dUW3/1oNL7sjyTLiWh82Xc/Wne1peg9DAAbk3LzshqtfiG+7J6Plx8L8eUarb7oPQwAGxOK9Sd6Zpe+u7tQPRA+YuWOWLlqG1c3tjDoihc9uHVQo9VH48uzwdhsMPa5id3XOCLD5yYWpSwJogIvcwwfd/ZtlcExfLzon8hG4/TIJh5FDwnIC/8Hawo+H8g7QoUAAAAASUVORK5CYII=" alt="" />

使用contentType="text/html; charset=GBK”时浏览器URL参数显示其他的编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xkGPCvz+Q4DKwHYRZlcUXCRM5Ng34d7hL1gfijtg2jIvGVKgrv7h5rX/G/D337ZvubBnnVL+jbdP7Dt/hvrf7V2+apdf3+488ASc8Iibey9yiOLajb9rLuQR+UxIQwh3ouBoHMJm8ZIWGxkUHAkl+KJHO3jdewUqPD53QvbFJvJrup7Ys/JXRfz2GLNyRLFJyWKj4vlHxUNnC5TYhK8KTaT6ly+T/NZkTHBy2NiCYnbVP2pkIjf+giKFeHu3wmaTrai0Elw3rXn7NqrE8lvz9GR7sMj0vcNnfv1HfuM3UcwCc679hxNL83FFSQP0lc3ybYvCfvFk4sQK5JCgic6mXibTztymEsw2eF47fPZtAXiTwhDQsOAMLgsJIxF2MLCSTA/FFzOSXeWiYWE771BFgr/D/EfIVGT1H/RAAAAAElFTkSuQmCC" alt="" />

不知道用的什么编码,但是知道春"和"节"的GBK编码分别是"B4 BA"和"BD DA"。于是试了试把“get提交”改成“get春节”

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAd4AAAArCAIAAABZ1H6KAAAM2ElEQVR4nO2c/XMTxxnH7+/ppO0PTdOJkjTppGHSlqRJSoYmlBBexpiQQAhJCEk8USFvZTqDIUMTICKSjG3i2DIgI4z1gl8wFsbEDn5B9skWtmWht7P1hi3JIuoPO96s9/ZWJ8n4jec7nx/Op93nnl3tfW9v72TBH5sFAAAAlhWCPzqrHu9ksnvIZ3MO1Nu7Ks1tFebWCnNrpbmt3t5lcw50D/kmplJ5BQQAAADkCHeis2oY9sds125VnG89a+/q6vd4fJJfSkQSqal40i8lPD6pq99z1t5Vcb7V3ukaCcRVhgUAAADk5LZm71Sq+Uex4nzLle4hKZacTv/MQYol27uHKs63tHS7J6bSS948AACAlUgOax72x2utnVZnfzg2wzdlklB0uqmjr9baOeyPLXkLAQAAVhyCLzqrhGtiqrLhyo0Bz93UzwXQ1e/5urqx+mLHuZZuAAAAQD2CLzLLZMgX1Z9tHhjxFebLiP5h3+mzttGx8XAodJ/IgEAg0KoT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E9bOuzXBwOxTJHYrw/WN7WHgrx1CbBmEAgEIiWMhNNM+r2xb00t111efyxTMM7+sYqzlycmFn4pA6wZBAKtYgkj4ZQS3Z7Q1zU22/XBO7HZArB2uv597Puva2yGhnYAAABAPTxrHgmnesemdPUttbauYX/8TnRWJcP+eI2t69TZ1lsTUerXhgAAAEBOhOFQis9QYOZ8W+/RqsaGtpvuQMIXmeUg+uPm1ptHqxrNbX1DgZmcwQEAAAA5ua0Z0TsWMTX3fFXVqDe3WTsHfxoJuAPx8cnU2GTK5Yv0DAesnYN6c9tXVY2m5p7esciSNwwAAGDlotaaEUP+6dabo7WO7u/OtR07Yz1cYTlcYTl2xvrdubZaR3frzdEh//SSNwkAAGClI7hDKQAAAGBZIbiDKQAAAGBZIYjBFAAAALCsAGsGAABYdoA1AwAALDvAmgEAAJYdYM0AAADLDrBmAACAZQdYMwAAwLKDbc1Xxmf0/Ymyzuh+Z2S/M1J2LWIYSFyfSC55ukXypdX9Vm0vhy+t7iVPshhGeg54rm7gMNJzYMmTXG4c7V1LseQpAcD/AXp5YMbHattCAAAAAElFTkSuQmCC" alt="" />

说明浏览器确实用的GBK将GET参数编码了,也就是说确实使用浏览器当前默认编码对GET参数编码

既然客户端是GBK编码,如果与POST方式一样tomcat用ISO-8859-1二次编码,那为什么在后台

String xx=new String(imageCode.getBytes("ISO-8859-1"),"GBK");用ISO-8859-1转GBK获取还是乱码呢?

说明我的tomcat获取GET参数不是用的ISO-8859-1二次编码,又因为GBK用UTF-8转码是转不过去的

原因GBK用UTF-8不能转码参照http://my.oschina.net/chape/blog/201725

而前面的用UTF-8测试的例子只有

String imageCode=request.getParameter("imageCode")和String y=new String(imageCode.getBytes("UTF-8"))

能取到正常值,所以我猜测tomcat直接用了UTF-8解码,也就导致了用过客户端用GBK后台用UTF-8转不了码,只能乱码了

于是我又做了个测试

在tomcat的server.xml里设置服务器编码URIEncoding="ISO-8859-1"

如果server.xml设置编码对GET方式有效的话,tomcat肯定是用ISO-8859-1二次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IAAACegkkDAAB4CiYNAADgKZg0AACAp2DSAAAAnoJJAwAAeAomDQAA4CmYNAAAgKdg0gAAAJ6CSQMAAHgKJg0AAOApmDQAAICnYNIAAACegkkDAAB4CiYNAADgKdKk/wVEJO7Vp3wDoQAAAABJRU5ErkJggg==" alt="" />

在原来的GBK中再次测试

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAN0AAACWCAIAAADVORriAAANd0lEQVR4nO2cb4wcZR3HJ0FjjBjfGBNf+cYEA5ISLC8cjh1NAa+JUopCAUsXSm8Oyl2x5a5SA51VkF6F1r2jQqUL22rNQalAuDKH4eIoOeCFi7d3r0xWnSMStZy3e1JEwmHGF7Mz88zzZ3Z2b2/n2bnvJ09yc8/O88wzz/PZ3zOz8+wqDsFbf3+fSg4ASaCQ/7BeQk2QCI29hJ2g88T1EgmpkwleIsmY4CWSjAleIsmY4npZAqCDNPbS3W/uraWUJcdxzKmSOVVqy/1jt+N2ReKD4qcGXqbSSF/KhByQF3nUjPIyrVLOvbUEKUVIouZa9NJBsBQju5elUml2fimVCVJGY04lP/TwEtCQXuZyuWxWI3svl8uJMuFlm73841+WNhqvf2P/a6J07QNv2GfXyiIBykvL0XwL3X8tRzMMOrOTXta4aei2Xf72nTcb/vbw9kFREakS62XP3lc36Y9c2/ewKG3qP/T1fa920I0kMaeCoXedcy3M5XKGodW9tIJMNyeXy7VxjFrxcufW4dn52hvP7TgxfP6J4fN/uff8P7x42+x8bde2PYk715qX63dNfWfHAzOLy6J0Y/9D63dNddANLtaQMmQ1U+BOj4aZJKyXRc/ColX3smjV1TS8nOS9zN5w3+x87eT3P/3R2Wfc9My+T87O126/aVh8pImsUif7tHReXnqXeX3fgzOLy6KhurH/oUvvMgUvWkPeqTWpTbO04mXDDRaul66apJd1NaO8nMtpCsHgk6vq5be/mZudr+Wznyj/4lNuOrL9vNn52pbr9kVI6ek4l9OaaF9nvLyk/4Xv7jwws7i8d2Ry532nt+0+cV3f41ff/Ii/w7aBg5f0v8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4GMwEsgI/ASyAi8BDLSaS85yzyo3/xdWf5qtBl0nk6vC+askzR117O25K+8zUAGOr0uGF6COHR6XTC8BHHo9LpgeAni0Ol1wfASxKHT64LhJYhDp9cF43MiEAesCwYygnXBQEbwHBLICLwEMiKFl4qitLAPlROnEtAtJOMleytNwS0SnQMv04Ts8bKhwb7H8DJNJOZlU8HSQbxcYyQfL2P6BC/XFAl4GX9qbrba1WgtSIQkfi/YP3ajEOhnxjEYXqaJxH4vOP51ZPSr8DKVJPB7wX6QEwW/iHkcXq4Rkvu94NjzeMwi8DJNJPd7weJ4GdVceLk2SPL3glcYLymP4WWaSOr3gh2nTfEyzkug60hyXXBbri/jlwVdRHrWBcPLNJH8c8h2AS/TBLwEMpIeL0GagJdARuAlkBF4CWQEXgIZgZdARuAlkBF4CWQEXgIZgZdARuAlkJH/A6HCcupky24+AAAAAElFTkSuQmCC" alt="" />

发现只有String xx=new String(imageCode.getBytes("ISO-8859-1"),"GBK");取到正常值

即修改server.xml编码对GET方式是有效的

其过程应该是客户端用GBK编码,服务器端用ISO-8859-1编码,我在servlet里手动用ISO-8859-1转码

这样看来我的tomcat在GET方式下默认编码应该是UTF-8,而不是网上很多人说的ISO-8859-1,

至于为什么是UTF-8我也不清楚,我用的tomcat8.0,JDK8,项目保存为GBK(UTF-8也试过)

!后来重新试验过,客户端使用的UTF-8,server.xml里指定ISO-8859-1二次编码,

在servlet里直接new String(imageCode.getBytes("ISO-8859-1")也能获取到正常值,String

里获取的ISO-8859-1编码后用的本地默认编码进行解码,本地默认编码就是你的.java文件保存的编码(在eclipse指的是workspace指定的编码),我保存为UTF-8,所以能获取到正常值,如果改为GBK则会乱码。

所以猜测servlet里解码采用的编码是你的平台默认编码!

隔了一段时间后我换了tomcat7,发现在server.xml默认没有编码的情况下,get和post提交在servlet里都是经过ISO-8859-1编码,与前面的结果不太一样,看来是tomcat版本不太,服务器采用的编码方式有所差异,

这样的话最好在tomcat的server.xml里指定get方式的二次编码为ISO-8859-1,在用过滤器统一编码的时候也方便处理

这样要想GET方式提交的参数不乱码最好的方式是在客户端使用UTF-8编码,如果一定要用其他编码,

最好用JS将参数编码为UTF-8再提交到后台

有一点需要知道:POST下的request.setCharacterEncoding("UTF-8")对GET方式无效

至于servlet中的响应编码使用response.setContentType("text/html;charset=utf-8")就可以了,该方法

指定HTTP的响应编码为UTF-8并通知浏览器以UTF-8编码显示。

总结:

1丶 不管get还是post方式提交的参数都是采用浏览器当前编码

2丶 针对tomcat7及以下版本,参数传入servlet后,两种方式默认情况下在servlet里采用ISO-8859-1解码,

针对中文,比如浏览器采用GBK,servlet可以使用new String(value.getBytes("ISO-8859-1"),"GBK")获取正确参数

  针对tomcat8版本,get方式提交的参数传入servlet后采用的平台默认编码解码

3丶 request.setCharacterEncoding()只对post方式有效,针对get方式,可以二次转码获取中文,或者在tomcat下的server.xml里指定编码

4丶 response.setCharacterEncoding()设置HTTP相应编码

response.setContentType()设置HTTP相应编码并通知浏览器解码方式