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

2 Answers 2

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" ...  />
Sign up to request clarification or add additional context in comments.

3 Comments

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.
What version of tomcat are you using in your setup? That's a really strange behaviour
Thank you Sir. It perfectly works. I don't know why, but when I install again my tomcat it just works fine
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.