I have everything in UTF-8. That includes Content-Type, database, files, java, everything (unless I've missed something).
I follow a lot of stackoverflow answers, JIRAs, blogs, and etc, but, it still failing.
The problem itself is the following:
When I submit, let's suppose, to http://localhost:8080/app/searh?text=café
, debugging, my request.getParameter("text")
is always wrong, something like café
, and request.getCharachterEncoding()
gives me null
(?).
Looking at the request headers, I got this:
GET http://localhost:8080/app/search?text=caf%C3%A9 HTTP/1.1
Host: localhost:8080
Proxy-Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.69 Safari/537.17
Referer: http://localhost:8080/app/search?text=n%C3%A3o
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: UTF-8,*;q=0.5
Cookie: JSESSIONID=OMMITED
And the response headers:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: No-cache
Cache-Control: no-cache
Expires: Wed, 31 Dec 1969 21:00:00 BRT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Content-Encoding: gzip
Vary: Accept-Encoding
Date: Tue, 19 Mar 2013 14:06:24 GMT
Proxy-Connection: keep-alive
Connection: keep-alive
It's everything UTF-8. I just don't understand.
I tried to pass -Dfile.encoding=UTF-8 -Dfile.io.encoding=UTF-8 -DjavaEncoding=UTF-8
in my standalone.conf
JAVA_OPTS
variable, tried to put
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
in my standalone.xml
. Nothing of this solves the issue.
What can I try to do to fix this?
Thanks in advance.
BTW: Is a JBoss AS 7.1.1.
I came into the same issue but in Jboss 5.1, and I solved it adding the URIEncoding attribute to the HTTP Connector (in jbossweb/server.xml) and decoding the URL/GET parameters manually.
But the way to define it in Jboss7 is different from previous versions, but googling a bit I found this link: basically you've to add the following lines in the standalone.xml or domain.xml file after the end of the </extensions>
tag (it looks like you've already done this step ;-):
<system-properties>
<property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
<property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
</system-properties>
Moreover you've to decode manually the URI or parameter with the help of the java.net.URIEncoder object:
String param = URLDecoder.decode(request.getParameter("text"), "UTF-8");
BalusC has an interesing post in his blog about it.
And finally, a second solution, if you want to avoid using the previous options: have you considered using the POST method instead of the GET one?
I hope it helps.
I solved the issue creating a Filter that set both request and response encoding to UTF-8.
Pretty hacky, but works.
I don't have enough reputation to add a comment to the answer by Toni S. Magraner, so I'll write here.
request.getParameter("text") already does the URL decoding. Calling URLDecoder.decode() again will give double decoding which will probably not do what you want. An example:
logger.error("p1:"+request.getParameter("p1"));
Calling it with
http://localhost/test?p1=ku%2fki%44__%33X%C3%A9X
prints:
p1:ku/kiD__3XéX
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With