1 Reply Latest reply on Mar 21, 2006 1:17 AM by ummadiravi78

    URGENT - request.setCharacterEncoding(

    ummadiravi78

      Hi,

      I use JBOSS-4.0.2.
      My application is struts based.

      When my action class receives form parameters, the request is not able to handle unicode characters.

      The unicode characters are getting displayed as some junk characters.
      I searched weba and everywhere it is written that "request.setCharacterEncoding("UTF-8")" should solve the problem. But strangely it's not working.

      I tried even with Tomcat5.0. Here is the JSP file I wrote to test unicode characters.

      JSP:

      
      <%@page contentType="text/html;charset=utf-8" pageEncoding="utf-8" import="java.io.*" %>
      <%
       String enc = request.getCharacterEncoding();
       if (enc == null)
       {
       request.setCharacterEncoding("UTF-8");
      
       }
      String characters = request.getParameter("str");
      out.println(characters);
      
      %>
      


      Even the above code is not able to handle unicode characters with tomcat 5.0.

      If I set URLENCODING attribute of CONNECTOR element in server.xml , then tomcat is able to handle encoding properly.

      But when I set URLENCODING attribute of JBOSS_TOMCAT's SERVER.XML, it is not able to handle unicode characters. I mean, when I pass unicode character from form, and if I read using "request.getParameter(
      "str") " it gives me junk characters in place of unicode character.

      Effectively, there is no way that I can get unicode characters from request in my JBOSS application.

      Please hlep me how I can solve this problem.,

      Ravi Prakash

        • 1. Re:  URGENT - request.setCharacterEncoding(
          ummadiravi78

          I solved this problem with the following two steps:
          1. adding the attribute useBodyEncodingForURI="true" to 'Connector' element of JBOSS_TOMCAT's server.xml
          2. Using request.setCharacterEncoding("UTF-8"); in the ServletFilter.

          It is weird to note that such things are not properly documented anywhere.

          -Ravi Prakash