POST提交,提交頁(yè)面顯示中文亂碼
1 2 3 4 | //設(shè)置請(qǐng)求的編碼格式 request.setCharacterEncoding( "utf-8" ); //設(shè)置響應(yīng)的編碼格式,與第一句的編碼格式重復(fù)指定了 //response.setCharacterEncoding("utf-8"); |
響應(yīng)編碼格式與JSP頁(yè)面設(shè)置的重復(fù),可不再設(shè)置了
1 2 | <%@ page language= "java" contentType= "text/html; charset=UTF-8" pageEncoding= "UTF-8" %> |
get提交,提交頁(yè)面顯示中文亂碼:
治標(biāo)的方法:新建一個(gè)字符串,獲取一個(gè)iso-8859-1的字符數(shù)組,然后轉(zhuǎn)為utf-8
1 2 | String username = request.getParameter( "username" ); String nn= new String(username.getBytes( "iso-8859-1" ), "utf-8" ); |
治本的方法:
在tomcat的配置文件:D:\apache-tomcat-7.0.70\conf\server.xml
<!--在下面8443中指定編碼格式URIEcoding="UTF-8"userBodyEncodingForURI="true" 用的是request.setCharacterEncoding("utf-8")--><Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443" 在這里添加/>
聯(lián)系客服