zoukankan      html  css  js  c++  java
  • Spring MVC 3 表单中文提交post请求和get请求乱码问题的解决方法

    在spring mvc 3.0 框架中,通过JSP页面、HTML页面以POST方式提交表单时,表单的参数传递到对应的servlet后会出现中文显示乱码的问题。解决办法可采用spring自带的过滤技术,对所有页面间参数的传递设置统一的字符编码。

    对于post请求:

    分两步解决问题:

    1.设置页面格式为UTF-8

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

     2.在web.xml中添加过滤器

    <!--spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET、POST、PUT与DELETE请求 -->
        
         <filter>  
          <filter-name>characterEncodingFilter</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>  
          <init-param>  
           <param-name>forceEncoding</param-name>  
           <param-value>true</param-value>  
          </init-param>  
        </filter>  
        <filter-mapping>  
          <filter-name>characterEncodingFilter</filter-name>  
          <url-pattern>/*</url-pattern>  
        </filter-mapping> 

    本文参考链接:http://blog.csdn.net/mybackup/article/details/7566590

    对于get请求:

    也是分两步解决:

    1.同上1步骤。

    2.在方法注解上设置produces值,如下:

    @RequestMapping(value="/selectPlaceListMap",produces = "text/html;charset=UTF-8")

    这样就解决了乱码问题。

  • 相关阅读:
    HTTP协议
    idea新建工程项目结构
    idea使用的JDK版本1.9换成1.8后相关的更改设置
    Servlet
    Tomcat三种项目部署方式
    Tomcat环境变量配置命令行报错:The JRE_HOME environment variable is not defined correctl This environment variable is needed to run this program
    JDBC面试题
    XML基础入门
    数据库连接池——Druid
    $.ajax 分页
  • 原文地址:https://www.cnblogs.com/sloveling/p/spring_post_get.html
Copyright © 2011-2022 走看看