Reading client-posted data via Tomcat servlet
Posted on 2003-11-03
I'm doing some simple client/servlet communication using Tomcat, using POST's via an HttpURLConnection.
I'm seeing my data at the servlet side via getInputStream(), but I can't decode it to a String, even by using InputStreamReader (which is supposed to do that). If I send a 5 character String, at the servlet I see "^@^@^@^@^@". I've tried constructing a String from a byte, but it doesn't decode, either.
I've tried writing the data as text with PrintWriter on the client side, and then reading text on the servlet side with getReader(), but getReader() returns null, even though a call to HttpServletRequest's getContentLength() returns non-zero (and shows the correct number of characters and/or bytes).
Reading the docs and api's leads me to believe this should be very straightforward, but it's just not working. I'm beginning to wonder if the problem is within Tomcat itself.
Any thoughts would be greatly appreciated!!!
Thanks in advance!