Spring encoding mvc path variables

I am using spring mvc. I surf:



please note that פת

is in Hebrew, not English.
My controller:

@RequestMapping(value="/services/cities/{name}", method=RequestMethod.GET)
public @ResponseBody List<SelectElement> getCities(@PathVariable String name) {
    List<SelectElement> elements=null;
    return elements;


The problem is the controller is receiving פת

and not the correct characters.
How can I fix this?

Even though I surf before: http://localhost:8080/services/cities/%D7%A4%D7%AA.html

I get this problem.


source to share

3 answers

If you are using tomcat you need to specify the url encoding for requests by adding URIEncoding="UTF-8"

in <Connector>

to your Tomcat config server.xml

as described here:




Here you have an interesting documentation of coding queries to Tomcat

Something like CharacterEncodingFilter will only work on POST requests. You need to change your Tomcat (or other container) configuration to use a URI other than ISO-8859-1. But this won't work in all browsers, it depends on how they encode the URIs too.

Therefore, my recommendation is always used as simply as possible. If you tell us what you are trying to achieve, maybe we can find a better solution (I suppose you don't need the user to also type the city name directly in the address bar).



Use a filter CharacterEncodingFilter






All Articles