The best place to ask programming/development questions, imo. UPDATE: stackoverflow is the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but a great reference for finding answers.

My Music (Nickleus)

20130902

[SOLVED] jboss 4.2.2.GA - character encoding problem when getting URL/URI parameter value

we have some code that gets a URL parameter value:
String savedSearchName = context.getExternalContext().getRequestParameterMap().get("name");

the URL looks like this:
http://localhost:9001/pages/listTRs.jsf?a=li&name=testsøk1

so even though the parameter looked like it had the right norwegian encoding (testsøk1), when we got the parameter value for "name", in java, the String savedSearchName had the following value:
testsøk1

to fix this we had to change the following file:
/path/to/jboss/server/mydomain/deploy/jboss-web.deployer/server.xml

and add a URIEncoding attribute to the <Connector> tag for the HTTP/1.1 protocol:

<Service name="jboss.web">
    <Connector port="9001"
        address="${jboss.bind.address}"
        URIEncoding="UTF-8"
        maxThreads="250"
        maxHttpHeaderSize="8192"
        emptySessionPath="true"
        protocol="HTTP/1.1"
        enableLookups="false"
        redirectPort="8443"
        acceptCount="100"
        connectionTimeout="20000"
        disableUploadTimeout="true" />
...
</service>


you have to restart your jboss sever for the change to take effect. after restart, the norwegian characters were correct in java:
testsøk1

No comments:

Post a Comment