码迷,mamicode.com
首页 > 编程语言 > 详细

spring mvc 中文参数乱码

时间:2016-07-07 12:50:46      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

最近做项目,springmvc的url中文参数乱码:

 

请求url:

http://localhost:8080/supply/supply_list.htm?productName=测试&isHomePage=

在后端:

@RequestMapping(value = SupplyURL.SUPPLY_LIST, method = RequestMethod.GET)
    public String toSupplyList (Model model, String productName) {

        PageBean<Supply> pagination = supplyFacade.querySupplyByPage(searchSupplyVO);
        
        model.addAttribute("searchSupplyVO", searchSupplyVO);return "/supply/supply_list";
    }

这里productName的值就变成了乱码,

检查我的web的web.xml中已经增加了过滤中文编码的:

 

<!-- Character Encoding filter -->
    <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>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

 

但是还是乱码。

 

仔细检查了,还是中间容器tomcat导致的。修改tomcat的conf/server.xml中的

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" useBodyEncodingForURI="true"/>

加上useBodyEncodingForURI="true"。即可

spring mvc 中文参数乱码

标签:

原文地址:http://www.cnblogs.com/gmq-sh/p/5649336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!