1、Tomcat中配置:C:\Tomcat 7.0\conf\servlet.xml配置 URIEncoding="utf-8"
2、 在servlet中处理
//处理乱码
response.setContentType("text/html;charset=utf-8");//设置响应文档类型
response.setCharacterEncoding("utf-8");//设置响应字符编码
request.setCharacterEncoding("utf-8");//设置请求编码
3、在jsp页中处理
String ss1=session.getAttribute("skill")+"";//也可以是request或application对象
new String(ss1.getBytes("iso-8859-1"),"utf-8")输出就不乱了
4、指令配置<% @ page contentType = " text/html;charset=utf-8 " %>
5、Servlet 过滤器
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request=(HttpServletRequest) arg0;
HttpServletResponse response=(HttpServletResponse) arg1;
//处理乱码
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
arg2.doFilter(request, response);//放行
6.工具中的Properties
网友评论