get请求:
修改tomcat/conf/server.xml中的
<Connector port="8989" ...... URIEncoding="utf-8" />
post请求:
servlet:
request.setCharacterEncoding("utf-8");
自定义filter
struts2:
系统拦截器,可以自动解决utf-8中的post中文乱码
springMVC:
在web.xml中 配置CharacterEncodingFilter
响应:
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
JSP:
<%@ page pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
HTML:
<meta http-equiv="content-type" content="text/html;charset=UTF-8"%>
万能: URLEncoder.encode(str, "utf-8");
修改tomcat/conf/server.xml中的
<Connector port="8989" ...... URIEncoding="utf-8" />
post请求:
servlet:
request.setCharacterEncoding("utf-8");
自定义filter
struts2:
系统拦截器,可以自动解决utf-8中的post中文乱码
springMVC:
在web.xml中 配置CharacterEncodingFilter
响应:
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
JSP:
<%@ page pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
HTML:
<meta http-equiv="content-type" content="text/html;charset=UTF-8"%>
万能: URLEncoder.encode(str, "utf-8");