美文网首页
中文乱码

中文乱码

作者: 打死你的小乌龟 | 来源:发表于2018-09-07 16:57 被阅读0次
    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
    

    相关文章

      网友评论

          本文标题:中文乱码

          本文链接:https://www.haomeiwen.com/subject/zhgcgftx.html