Java servlet and UTF-8 problem

Posted by Gabriele on Stack Overflow See other posts from Stack Overflow or by Gabriele
Published on 2010-06-12T16:51:40Z Indexed on 2010/06/12 17:03 UTC
Read the original article Hit count: 494

I have some problem with UTF-8. My client (realized in GWT) make a request to my servlet, with some parametres in the URL, as follow:

http://localhost:8080/servlet?param=value

When in the servlet I retrieve the URL, I have some problem with UTF-8 characters. I use this code:

protected void service(HttpServletRequest request, HttpServletResponse response) 
                    throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");

        String reqUrl = request.getRequestURL().toString(); 
        String queryString = request.getQueryString();
        System.out.println("Request: "+reqUrl + "?" + queryString);
        ...

So, if I call this url:

http://localhost:8080/servlet?param=così

the result is like this:

Request: http://localhost:8080/servlet?param=cos%C3%AC

What can I do to set up properly the character encoding?

© Stack Overflow or respective owner

Related posts about java

Related posts about servlets