1

I have some fields with special characters. When I pass those fields from JSP by submiting the form to Springs Controller then it is displayed as shown below.

á - á
é - é
í - Ã
ó - ó
ú - ú
ñ - ñ

I tried few things like putting some encoding 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>

Encoding in Controller like,

request.setCharacterEncoding("UTF-8");

Still I am not able to solve the issue. Please Help.

Thanks in advance.

Note: I checked some of the questions related this question in our stackoverflow, Still not able to find it. Character encoding JSP -displayed wrong in JSP but not in URL: "á » á é » é"

Community
  • 1
  • 1
Max
  • 1,334
  • 5
  • 16
  • 34
  • 1
    Is it `get` or `post` query? Do you have some other filters? Also see http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html – axtavt Jun 21 '11 at 08:08
  • @axtavt: Thanks a lot buddy, this solved my problem. I added Filters in web.xml and kept method 'post' and everything is working fine. Please post this as answer will approve. – Max Jun 21 '11 at 10:07
  • I don't think it's an answer on its own. – axtavt Jun 21 '11 at 11:35
  • hmm... but suggestion helps. Anyway thanks buddy – Max Jun 21 '11 at 11:38

1 Answers1

3

This filter works for POST requests only. For GET requests you'd need to configure it at servletcontainer level. In case of for example Apache Tomcat, you'd need to edit the <Connector> entry in /conf/server.xml to add the URIEncoding="UTF-8" attribute.

<Connector URIEncoding="UTF-8" ... />

Calling request.setCharacterEncoding("UTF-8"); manually has no effect as the filter is already doing that.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555