3

i have a spring roo webapplication running in tomcat 7. there i have a spring roo generated controller method, that i pushed in for debugging issues:

@RequestMapping(params = "find=ByFirstNameEqualsAndLastNameEquals", method = RequestMethod.GET)
public String findAuthorsByFirstNameEqualsAndLastNameEquals(
        @RequestParam("firstName") String firstName,
        @RequestParam("lastName") String lastName,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "size", required = false) Integer size,
        @RequestParam(value = "sortFieldName", required = false) String sortFieldName,
        @RequestParam(value = "sortOrder", required = false) String sortOrder,
        Model uiModel
        ) {

    System.out.println("find author lastname: " + lastName);
    String lastNameUTF8 = null;
    String firstNameUTF8 = null;
    try {
        lastNameUTF8 = new String(lastName.getBytes("ISO-8859-1"), "UTF-8");
        System.out.println("lastnameUTF8: " + lastNameUTF8);
        firstNameUTF8 = new String(firstName.getBytes("ISO-8859-1"),
                "UTF-8");
        System.out.println("lastnameISOtoUTF8: " + firstNameUTF8);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
            ...

as one can see at the logs:

  find author lastname: ШÑ<U+0082>Ñ<U+0080>ембеÑ<U+0080>г
  lastnameISOtoUTF8: Штремберг

the requestparameters firstName and lastName come in encoded as ISO-8859-1, but i expected them UTF-8 encoded. i think i saw most of similar questions

and made sure to have all the confurations set to UTF-8:

web.xml:

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

tomcats server.xml:

...
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" 
          URIEncoding="UTF-8"
...
<!-- Define an AJP 1.3 Connector on port 8009 -->
 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" 
   URIEncoder="UTF-8"
/>

java arguments:

/usr/local/jdk7/bin/java -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8 /usr/local/tomcatODM_TEST/bin/bootstrap.jar:/usr/local/tomcatODM_TEST/bin/tomcat ...  org.apache.catalina.startup.Bootstrap start

also browser encoding is set to UTF-8, system LANG on server and client:

$ echo $LANG  en_US.utf8

i don't have any clue what else to do to get rid of that funny ISO-8859-1 decoding of spring mvc i guess... any ideas? what am i overlooking?

4
  • what about the browser? Commented Sep 10, 2014 at 10:19
  • was one of the first things i checked: its encoding set to UTF-8 also. tested with different browser. i guess that's the wrong place to look, because i get UTF-8 encoded as ISO-8859-1. Commented Sep 10, 2014 at 18:05
  • and what about the html? Commented Sep 10, 2014 at 21:20
  • <html><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/> i guess that's also the wrong place to look, because i get UTF-8 encoded as ISO-8859-1. Commented Sep 12, 2014 at 7:02

1 Answer 1

1

I had the same issue and after much research realised it was the Tomcat connector which was the issue. I tried everything but only adding the following fixed it to the "server.xml"

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

It's annoying that you can't set something in Spring to set the URIEncoding.

Also, initially the <connector ... URIEncoding="UTF-8"/> update didn't work but it was because my Tomcat "server.xml" was being overriden so make sure that isn't the case.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right. somehow it was overwritten... thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.