tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Mannion" <chris.mann...@nonstopgov.com>
Subject Odd encoding of servlet parameters
Date Thu, 27 Nov 2008 10:17:43 GMT
Hi All

I've recently started having a problem with one of the servlets I'm
running on a Tomcat 5.5 system.  The code of the servlet hasn't
changed at all so I'm wondering if there are any Tomcat settings that
could affect this kind of thing or if anyone has come across a similar
problem before.

The servlet in question accepts XML data that is posted to it as a URL
parameter called 'xml'.  The code to retrieve the XML as a String
(which is then used to build a document object) is simply -

String xmlMessage = req.getParameter("xml");

- where req is the HttpServletRequest object.  Until recently this has
worked fine with the XML being received properly formatted -
<?xml version="1.0" encoding="UTF-8"?>
  <records>
    <record>...
etc.

However, recently something has changed and the XML is now being
retrieved from the request object with escape characters in, so the
above has become -
&lt;xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;records&gt;
    &lt;record&gt;

Before sending the XML is encoded using the java.net.URLEncoder object
and the UTF-8 character set, but using a java.net.URLDecoder on
receiving it does not get rid of the encoded characters.  I did some
reading about a possible Tomcat 6.0 bug and so tried explicitly
setting the character encoding (req.setCharacterEncoder("UTF-8"))
before retrieving the parameter but that had no effect either and even
if there's something that could explicitly decode the &lt; &gt; etc. I
couldn't use it as the XML data often contains characters like &amp;
which have to remain encoded to keep the XML valid.

As I said, this problem started without the servlet code having
changed at all so is there any Tomcat setting that could be
responsible for this?

-- 
Chris Mannion
iCasework and LocalAlert implementation team
0208 144 4416

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message