Search code examples
spring-mvcencodingurlencodediacriticscuba-platform

Post a values with umlauts(äöü) to Cuba Portal App Spring MVC Controller


I have some with the binding in Spring MVC Controller (@ModelAttribute("name") String name)

@RequestMapping(value = "/authors", method = RequestMethod.POST)
public String index(
        @ModelAttribute("name") String name) {...}

Post auf .../authors Form data: name=Näöüme

In controller name:Näöüme

If i get the requests inputstream the name=N%C3%A4%C3%B6%C3%BCme is URLEncoded.

Is there a way to set the urlencoding?


Solution

  • I found the solution, I have to set the filterEncoding in web.xml:

     <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>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>