users@glassfish.java.net

Re: How do I change the URI encoding to UTF-8 in Glassfish

From: <glassfish_at_javadesktop.org>
Date: Fri, 14 Mar 2008 06:38:34 PST

Yeah, I still can't get it to work either. I made a very simple servlet to test the encoding, here it is:

public class EncodingServlet extends HttpServlet {
   
    /**
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet EncodingServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("parameter from get is: " + request.getParameter("test") +
            "<br />");
            out.println("but should have been: á<br />");
            out.println("</body>");
            out.println("</html>");
        
        } finally {
        
            out.close();
        
        }
    }

   
    /**
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    
}

Made the following adjustments to the domain.xml file:

Added the "<property name="uriEncoding" value="UTF-8"/> to the http-listeners on ports 8080 and 8081. I also added that property to http-service. Additionally, I changed the forced-type and default-type attributes in http-protocal (http://docs.sun.com/app/docs/doc/819-3674/abhcp?l=en&a=view) to use UTF-8.

Then I use the following url: http://localhost:8081/EncodingExample/EncodingServlet?test=%C3%A1, where %C3%A1 is the hex value of á in UTF-8. the servlet returns á for á.

Is there something I am missing? I looked through all the other properties, these seemed to be the only ones that contained anything about url encoding. Thanks
[Message sent by forum member 'tbarker9' (tbarker9)]

http://forums.java.net/jive/thread.jspa?messageID=264027