Loading... # Servlet 编码问题 Servlet获取参数编码的问题,在8.0之前,tomcat默认的编码是`ISO-8859-1`的,tomcat在8.0以后,默认的编码就变成`UTF-8`了 所以在tomcat8.0后的版本都不需要处理Get方式的编码问题,而POST方式还是需要设置一下 request的编码就可以了 这里讲的是Tomcat8.0以前的版本 |--|--| |数据来源|编码格式| |浏览器页面|GBK| |request(Get)|ISO-8859-1| |request(Post)|GBK,Servlet可以设置接受格式| |response|ISO-8859-1| # 处理中文的方法 **request(Get):**: ```java String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8"); ``` **request(POST)** ```java request.setCharacterEncoding("UTF-8"); ``` **response** ```java response.setContextType("text/html;charset=utf-8"); ``` Last modification:September 16th, 2019 at 03:52 pm © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat