JSP传参(post方式)乱码问题

JSP的页头:<%@ page contentType="text/html; charset=UTF-8" language="java"  import="java.sql.*"
 errorPage=""%>
<meta http-equiv="Content-Type" content="text/html; charset=SJIS" />
<% request.setCharacterEncoding("UTF-8"); %>

 

Tomcat的server.xml中:    <Connector port="8080" protocol="HTTP/1.1"
               maxThreads="150" connectionTimeout="20000"
               redirectPort="8443"  URIEncoding="UTF-8" useBodyEncodingForURI="true"/>

 

url传参时:<a href="go?name1=<%=URLEncoder.encode("你好","UTF-8") %>&name2=<%=URLEncoder.encode("前払金 ","UTF-8") %>&name3=abc">go</a>

 

Servlet端获取值时:String name1 =new String(request.getParameter("name1").getBytes("ISO-8859-1"),"UTF-8");

String name2 =new String(request.getParameter("name2").getBytes("ISO-8859-1"),"UTF-8");

String name3 =new String(request.getParameter("name3").getBytes("ISO-8859-1"),"UTF-8");

 

打印出来的结果:name1:你好      ------中文传参

                                name2:前払金   ------日文传参

                                name3:abc      -------英文传参

利用这种方法,其实只要是utf-8能显示的字符,无论是什么语种,都可以传参显示,没有乱码。

你可能感兴趣的:(sql,tomcat,jsp,SQL Server,Go)