Spring encoding mvc path variables
I am using spring mvc. I surf:
http://localhost:8080/services/cities/פת.html
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
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).
source to share
Use a filter CharacterEncodingFilter
...
<filter>
<filter-name>CharacterEncodingFilter</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>
source to share