tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Jarman <ajar...@metacomcorp.com>
Subject RE: Unable to POST to my servlet (DESPARATE!)
Date Sat, 16 Sep 2000 17:27:43 GMT
A HUGE thank you.  I have been beating my head against the wall trying
to figure this one out.  

Interestingly enough, the web-to-go servlet runner that's in JDeveloper
3.1 will hang when trying to use this code.  It seems to want the
ready() test.  We currently edit code on JDeveloper, then deploy to
TomCat.  I will have to fix this so we are actually using Tomcat in the
debugger.

Cheers,
Andrew


-----Original Message-----
From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Friday, September 15, 2000 7:42 PM
To: tomcat-user@jakarta.apache.org
Subject: Re: Unable to POST to my servlet (DESPARATE!)


Try it without the "ready()" test, which doesn't really accomplish
anything
for you.  You can also simplify a little in other ways, but this is the
most important issue.

    int sizeOfBuffer = 100;
    char[] cbuf = new char[sizeOfBuffer];
    StringBuffer inputBuffer = new StringBuffer();
    BufferedReader reader = request.getReader();
    int chars = 0;
    while ((chars = reader.read(cbuf)) >= 0) {
        inputBuffer.append(cbuf, 0, chars);
    }
    reader.close();

Craig McClanahan


Andrew Jarman wrote:

> Hi,
>
> I have a servlet that needs to process XML data sent from a client
> browser.  The xml is not sent as a form post, but rather as direct
XML.
> This requires me to get the raw text sent in, so I can't use
> getParameter.
>
> I made a simple 'Echo' servlet that simply replies back what I've sent
> in.  When I run this on JDeveloper 3.1 using their WebToGo servlet
> runner, it works perfectly.  When I try it in Tomcat, I don't get
> anything at all.  (input is empty).  I have tried this on Tomcat 3.1,
> 3.2B2 and 3.2B4 with the same results.
>
> PLEASE PLEASE somebody give me a hand.  I have a major integration to
> complete this weekend, and this is the last sticking point.
>
> I believe the Webtogo server is implementing Servlet 2.0, and Tomcat
is
> implementing 2.2
>
> Any assistance is deeply appreciated.
>
> ---------------------------------------
> Servlet doPost method
>
>         public void doPost(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
>                 response.setContentType("text/html");
>                 PrintWriter out = new PrintWriter
> (response.getOutputStream());
>                 out.println("<html>");
>                 out.println("<head><title>Echo</title></head>");
>                 out.println("<body>");
>
>                 int sizeOfBuffer = 100;
>                 char[] cbuf = new char[sizeOfBuffer];
>                 int offset = 0;
>                 int length = sizeOfBuffer;
>                 int charactersRead = 0;
>                 StringBuffer inputBuffer = new StringBuffer();
>                 BufferedReader inputStreamReader =
request.getReader();
>
>                 while ( (inputStreamReader.ready()) &&
>                         (charactersRead = inputStreamReader.read(cbuf,
> offset, length)) != -1) {
>                         inputBuffer.append(cbuf, offset,
> charactersRead);
>
>                         // display what's coming in for debugging
>                         out.println("Reading... " +
> inputBuffer.toString());
>                 }
>
>               inputStreamReader.close();
>
>                 out.println(inputBuffer);
>
>                 out.println("</body></html>");
>                 out.close();
>         }
>
> ---------------------------------------
> Web page that generates the input
>
> <HTML>
>   <HEAD>
>     <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> charset=WINDOWS-1252">
>     <META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
>     <TITLE>XML Protocol Adapter - Test 1: Submitting SOAP or HTTP/HTML
> content</TITLE>
>   </HEAD>
>
>   <BODY>
>     <INPUT TYPE="text" ID="server" STYLE="width: 100%;"
> VALUE="http://db2.metacomcorp.bogus:8080/servlet/adapter"/>
>     <TEXTAREA ROWS="5" STYLE="width: 100%;"
> ID="request">&lt;browse/&gt;</TEXTAREA>
>     <BUTTON ONCLICK="var http = new
ActiveXObject('Microsoft.XMLHTTP');
>                      http.open('POST', document.all.server.value,
> false);
>                      http.send(document.all.request.value);
>                      document.all.result.value = http.responseText;"
>             >Send</BUTTON>
>     <TEXTAREA ROWS="15" STYLE="width: 100%;" ID="result">Result goes
> here.</TEXTAREA>
>   </BODY>
> </HTML>

--
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat


Mime
View raw message