• 【Java】【jquery】ajax垃圾问题



    1、暗示HTML、JSP文件本身使用UTF-8格公式

    2、HTML的head加:

         <META http-equiv="Content-Type" content="text/html; charset=UTF-8">   

    3、JSP文件头添加

         <%@ page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>  

    4、当中第2、3点也可通过Filter实现:

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        if (req.getHeader("X-Requested-With") != null && req.getHeader("X-Requested-With").equalsIgnoreCase("XMLHttpRequest")) {
            request.setCharacterEncoding("utf-8");
        } else {
            request.setCharacterEncoding("gbk");
        }
        chain.doFilter(request, response);
    }


    5、在你的tomcat或者jboss的server.xml文件里Connector标签下加上:URIEncoding="UTF-8"

          这一点是关键、一般中间件默认的编码格式是iso8859-1、iso8859-1能显示中文。可是对中文的支持不是非常好,有些生僻字无法显示。

          假设没有这一步的设置就须要採用下面方法转码:new String(request.getParameter("chnlName").getBytes("iso8859-1"),"utf-8")


    
    

    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    十问5.12汶川大地震
    JZ035数组中的逆序对
    JZ037数字在排序数组中出现的次数
    JZ039平衡二叉树
    JZ033丑数
    JZ040数组中只出现一次的数字
    JZ032把数组排成最小的数
    JZ036两个链表的第一个公共结点
    JZ034第一个只出现一次的字符位置
    JZ031从 1 到 n 整数中 1 出现的次数
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4845053.html
Copyright © 2020-2023  润新知