0

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

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

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

USER_JVM
  • 69
  • 4
  • 14

2 Answers2

1

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" ...  />
kellyfj
  • 6,586
  • 12
  • 45
  • 66
Abel Pastur
  • 1,905
  • 2
  • 24
  • 31
  • Yes Sir. This is absolutely right. But I tried it before. The problem is that connector server.xml rewrite itself on each reboot of container. I tried to install autoDeploy="true" to false, but it is keep do same things againg. – USER_JVM Jul 23 '13 at 16:02
  • What version of tomcat are you using in your setup? That's a really strange behaviour – Abel Pastur Jul 23 '13 at 16:05
  • Thank you Sir. It perfectly works. I don't know why, but when I install again my tomcat it just works fine – USER_JVM Jul 23 '13 at 16:24
0

Only certain way I found to do this without changing Tomcat configuration is:

put parameter in form

<form onsubmit="encodeParameter(this.param)">
  <input type="text" name="param" />
  <input type="submit" />
</form>

and then encode it before submitting to server

function encodeParameter(param){
  param.value =encodeURIComponent(param.value);
}

now on server you will get correct string.

Vuk Djapic
  • 816
  • 13
  • 29