a、设置页面编码,若是jsp页面,需编写代码
<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
若 是 html 页 面 , 在 网 页 头 部 ( < head>< /head> ) 中 添 加 下 面 这 段 代 码
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
b 、 将 form 表 单 提 交 方 式 变 为 post 方 式 , 即 添 加
method="post";
在 Servlet 类 中 编 写 代 码,而且必须写在第一行。
request.setCharacterEncoding("UTF-8")
c 、 如 果 是 get 请 求 , 在 Servlet 类 中 编 写 代 码
byte [] bytes = str.getBytes("iso-8859-1");
String cstr = new String(bytes,"utf-8");
或者直接修改Tomcat服务器配置文件server.xml增加内容:
URIEncoding="utf-8"