2 Replies Latest reply on Nov 4, 2004 8:25 AM by mbeyer73

    httpServletRequest.getParameter decoding problem

    ybenigot

      Using jboss 3.2.3 with tomcat on Linux/Intel

      I send an HTTP GET with header Content-Type: text/xml ; charset=utf-8 to a servlet using apache HttpClient.

      The parameters values are encoded with URLencoder.urlencode(value,"UTF-8").

      -> In the servlet, request.getParameter(parameterName) returns a String
      with malformed text : accented characters are replaced by pairs of special characters.


      If I use URLencoder.urlencode(value,"ISO-8859-1") on the client side it
      works just fine.


      So I guess jboss is using the defaut 8859 encoding on the server side, instead of the HTTP header information.

      Is there a way to fix this ?

        • 1. Re: httpServletRequest.getParameter decoding problem
          mbeyer73

          I am having the same problem with JSP pages using JBoss 3.2.5 on Win XP. The parameters are always decoded in ISO-8859-1. I even tried an Encoding-Filter with no success.

          Demo page:

          <%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
          <%@ page import="java.net.URLEncoder" %>
          
          <% request.setCharacterEncoding("UTF-8"); %>
          
          <title>Test</title>
          
          <h1>Umlaut-Test! öäüß</h1>
          
          <form method="get" action="test.jsp">
          <input type="hidden" name="p" value="Müller" />
          <input type="submit" value="submit! (UTF-8, see contentType)" />
          </form>
          
          <p><a href="test.jsp?p=<%= URLEncoder.encode ("Müller", "UTF-8") %>">LINK encoded in UTF-8</a></p>
          <p><a href="test.jsp?p=<%= URLEncoder.encode ("Müller", "iso-8859-1") %>">LINK encoded in iso-8859-1</a></p>
          
          <h1>Result</h1>
          <p>request.getCharacterEncoding ( ) &ndash; <%= request.getCharacterEncoding ( ) %></p>
          <p>request.getParameter ("p") &ndash; <%= request.getParameter ("p") %></p>
          


          • 2. Re: httpServletRequest.getParameter decoding problem
            mbeyer73

            It seems that Tomcat ignores request.setCharacterEncoding. The request char encoding however can be set globally in server.xml, tag "Connector", attribute URIEncoding, e.g.

             <Connector port="8080" address="${jboss.bind.address}"
             maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
             enableLookups="false" redirectPort="8443" acceptCount="100"
             connectionTimeout="20000" disableUploadTimeout="true"
             compression="on" compressionMinSize="2048" compressableMimeType="text/html,text/xml"
             URIEncoding="UTF-8"
             />
            


            My goodness, I spent two days two find that out :-( Why don't do the Tomcat developers follow the spec? Or at least write out a warning or throw an exception if I call request.setCharacterEncoding ("pleaseIgnoreMe")?

            angry,
            Marcus