zoukankan      html  css  js  c++  java
  • spring表单—乱码解决方案

    1.POST方式提交

    A.jsp页面POST方式提交表单

    B.web.xml配置过滤器

      <!-- spring过滤器解决乱码问题 -->
      <filter>
          <filter-name>encodingFilter</filter-name>
          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
          <init-param>
              <param-name>encoding</param-name>
              <param-value>UTF-8</param-value>
          </init-param>
      </filter>
      <filter-mapping>
          <filter-name>encodingFilter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>

    C.保证文件的编码格式(文件上按右键选Properties里的编码格式)、JSP的pageEncoding、charset的编码必须跟过滤器的编码一致

    2.GET方式提交

    如果采用post提交,会走Filter,但是如果是用get方式,是不走Filter的,所以在后端会变成乱码,解决方案有两条。

    A.一种是设置tomcat的server.xm里面的connector,效果如下:

    <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" URIEncoding="UTF-8" />

    B.一种是在提交的时候利用javascript的encodeURI进行编码

  • 相关阅读:
    jQuery实现 自动滚屏操作
    jQuery实现全选、全不选以及反选操作
    读曾国藩
    把时间当作朋友 之感知时间
    把时间当作朋友4未知永远存在
    Android N 设置中语言列表介绍
    如何编译ICU资源
    idea常用快捷键
    shell 笔记
    Json笔记
  • 原文地址:https://www.cnblogs.com/57rongjielong/p/7818826.html
Copyright © 2011-2022 走看看