1、
<% // 以 GET 方式提交数据时
// 读取用户名和密码
String name = request.getParameter("name");
// 对请求数据进行字符编码
name = new String(name.getBytes("ISO-8859-1"), "utf-8");
%>
2、
<%// 以 POST 方式提交数据时
// 设置读取请求信息的字符编码为 UTF-8
request.setCharacterEncoding("utf-8");
//读取用户名和密码
String name = request.getParameter("name");
String pwd= request.getParameter("pwd");
%>
3、
在 Tomcat 目录结构 \conf\server.xml 中设置字符集
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"
/>