You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Bo Min Jiang <bj...@cambian.com> on 2002/06/05 00:44:59 UTC

Differences in XML data received by servlet in Tomcat?

Hi,

I have a simple Java client that uses HTTP Post to pass an XML string to a
servlet on Tomcat.  This is done with a HttpURLConnection and writing to a
DataOutputSteam. The string looks like the following:

xmldocument=<?xml version="1.0"
encoding="UTF-8"?><AdvancedSearch>test</AdvancedSearch>

In my servlet, when I call getParameterNames() on the request, I get the
following:

parameter name: "1.0" encoding 
parameter value: "UTF-8"?><AdvancedSearch>test</AdvancedSearch>

These values are not what I expected.

However, when I call the same servlet with the same data using a browser
(IE5), I get the correct values

parameter name: xmldocument
parameter value: <?xml version="1.0"
encoding="UTF-8"?><AdvancedSearch>test</AdvancedSearch>

Both calls use "application/x-www-form-urlencoded" as the content-type.  I
also tried to explicitly encode the string passed by the Java client using
URLEncoder.encode() but that didn't work.

Does anyone have any idea why these differences occur?  Is there something
significantly different between how a browser and a standalone client do a
HTTP post, besides some header info?  Also, if anyone knows of a simple
example demonstrating posting XML to a servlet in Tomcat, it would be great
if you could refer me to it.

Thanks,
Bo