I've some issues with my Java Servlet if it's called with special chars (like Æ, Ø og Å) in the GET-parameters: http://localhost:8080/WebService/MyService?test=Øst.
I than have this code in my doGet
:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println(request.getParameterValues("test")[0]);
}
The messages printed in the console is: Ã?st.
The Web Service should be able to handle calls like this. How can I encode the parameter values in a proper way?
This needs to be configured at servet level. It's not clear which one you're using, so I'll give examples for Tomcat and Glassfish only.
Tomcat: add
URIEncoding
attribute to<Connector>
element in/conf/server.xml
:Glassfish: add
<parameter-encoding>
to/WEB-INF/glassfish-web.xml
(orsun-web.xml
for older versions):See also:
you should be percent encoding special characters (http://en.wikipedia.org/wiki/Percent-encoding). In your example above, the "slashed O" (Ø) has the UTF-8 code 0xd8, so your URL would properly be written:
http://localhost:8080/WebService/MyService?test=%d8st.
Which should result in
being printed to the console, from your servlet code above.
You could try the following code before requesting parameters: