Question

In my controller, I have this method:

@RequestMapping(value = "/find-by-company-name/{companyName}", method = RequestMethod.GET)
public CustomerDto findByCompanyName(@PathVariable String companyName){
    return customerService.findByCompanyName(companyName);
}

When I use URL like this /find-by-company-name/Mestská%20knižnica then I get Mestsk?? kni??nica in companyName variable.

Is there any solution to this issue?

In web.xml I use:

<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>
</filter>

<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
Was it helpful?

Solution

The solution was to add URIEncoding="UTF-8" to server.xml configuration file, like this:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" 
           URIEncoding="UTF-8" />

OTHER TIPS

Your URL should be encoded, like the space %20 is. Then encoding will be ok.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top