本文介绍了Spring MVC URIEncoding无法正确发送requestparam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从浏览器向Spring MVC控制器发送一些请求参数,然后像方法参数一样处理它们.问题是我想tomcat没有正确编码通过的URI数据.代替了'Имя',我得到了:%D0%9C%D0%91%D0%94%D0%9E%D0%A3+%D0%B4%2F%D1%81%E2%84%969%D1%81.+%D0%95%D0%BB%D0%B8%D0%BE%D0%BD%D0%BA%D0%B0

I need to send some request parameters from browser to Spring MVC controller and process them later like method parameters. The problem is that tomcat I guess didn't put right encoding for URI data which passing through. Instead of 'Имя' I'm having: %D0%9C%D0%91%D0%94%D0%9E%D0%A3+%D0%B4%2F%D1%81%E2%84%969%D1%81.+%D0%95%D0%BB%D0%B8%D0%BE%D0%BD%D0%BA%D0%B0

我曾经阅读过这种类型的问题,这是由于tomcat没有预安装URI编码而发生的.

I use to read about this type of problem which occurs because of tomcat does not have URI encoding preinstalled.

如果您介意我在tomcat config web.xml中有正文编码,那么是的,我有:

If you mind do I have body encoding in tomcat config web.xml, so Yes I have:

<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>tru?</param-value>
        </init-param>
    </filter>

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

所以我很好奇我是否需要对容器配置进行其他设置?谢谢

So I'm curious do I have to set up anything else to container config.? Thank you

推荐答案

您必须在tomcat配置目录内的server.xml文件中为HTTP连接器设置URIEncoding属性:

You have to set the URIEncoding attribute for the HTTP connector in server.xml file inside your tomcat config dir:

<Connector port="8080" URIEncoding="UTF-8" ...  />

这篇关于Spring MVC URIEncoding无法正确发送requestparam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 20:26