• 问题url传参中文乱码


    我们知道tomcat的默认编码是iso8859-1,在上面跑web项目时需要注意编码问题。于是我在过滤器中写好了编码转换,将其转换成utf-8,配置文件中映射了所有根目录的文件

    (<url-pattern>/*</url-pattern>)。之前做的都是表单提交,中文什么的一切OK。然而今天我在做下拉分类菜单,要保留选中的菜单条目是用到了url传中文参数,出现了乱码问题<-----get方法。无奈只能在该功能页中多写了一句:

      String typeChooseName = req.getParameter("typeChooseName");
      typeChooseName = new String(typeChooseName.getBytes("ISO-8859-1"), "UTF-8");

    来进行编码转换。

    想知道为什么Filter没有过滤  get  方法中参的参数 ,而post方法是有过滤的

    以下是我在Filter过滤器中写的编码转换

    public class EncodingFilter implements Filter {
       String encoding = "utf-8";

       public void init(FilterConfig filterConfig) throws ServletException {
       }

       public void doFilter(ServletRequest request, ServletResponse response,
         FilterChain chain) throws IOException, ServletException {
          request.setCharacterEncoding(encoding);
          response.setCharacterEncoding(encoding);
          chain.doFilter(request, response);
       }

       public void destroy() {
       }

    }

  • 相关阅读:
    两种存储思路
    越来越浅
    我了解的前端史
    关于称赞小孩
    怎么写递归
    Python笔记(十八):协程asyncio
    网络协议笔记(一):HTTP协议基础知识
    Linux笔记(三):常用命令
    算法笔记(九):二分查找
    数据结构笔记(二):栈、队列
  • 原文地址:https://www.cnblogs.com/xumz/p/7404338.html
Copyright © 2020-2023  润新知