Hi Folks,

Never Mind. Solved the problem.

Thanks,
Dinesh
-----Original Message-----
From: Dinesh V [mailto:[EMAIL PROTECTED]
Sent: Sunday, January 11, 2004 1:19 AM
To: [EMAIL PROTECTED]
Subject: ServletInputStream comes up closed.


Hello Folks,

I am experiencing a problem with my dump servlet.  The servlet simply echoes
back the content it recieved. The ServletInputStream comes up closed
(inputStream.available() returns 0).  I do not understand what is consuming
the input.  This does not happen on jetty 4.2.14.  Please tell me what am I
doing wrong.

I have tried Tomcat 4.1.29 and 5.0.16 on Win 2K and JDK 1.4.2_01

TIA,
Dinesh

package servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class upload extends HttpServlet {
  public void doPost(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
    InputStream is = request.getInputStream();
    OutputStream os = response.getOutputStream();
    os.write(new String("Following data was
posted<br>").getBytes("US-ASCII"));
    int chrsRead = 0;
    while (is.available() > 0) {
      int j = is.read();
      StringBuffer sb = new StringBuffer();
      switch (j) {
        case '<': sb.append("&lt;");break;
        case '>': sb.append("&gt;");break;
        case '&': sb.append("&amp;");break;
        case '\n': sb.append("<br>");break;
        default: sb.append((char)j);break;
      }
      for (int i = 0; i < sb.length(); i++)
        os.write(sb.charAt(i));
      chrsRead++;
    }
    os.write(new String("<br>Total chars read =
"+Integer.toString(chrsRead)).getBytes("US-ASCII"));
    os.close();
    os.flush();
  }
}

Deployment descriptor is here:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd";>

<web-app>
  <display-name>XMLHttp Request Response</display-name>
  <description> Http Req Resp </description>
  <servlet>
    <servlet-name>upload</servlet-name>
    <servlet-class>servlet.upload</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>upload</servlet-name>
    <url-pattern>/upload</url-pattern>
  </servlet-mapping>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>upload</web-resource-name>
      <url-pattern>/http/*</url-pattern>
      <http-method>GET</http-method>
      <http-method>POST</http-method>
    </web-resource-collection>
    <user-data-constraint>
      <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
</web-app>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to