Hi Nic Ferrier,

Thank you for your suggestion. I tried out the code snippet that you had suggested by 
making a servlet to contain that code and called it using <FORM METHOD=POST 
ACTION="/servlet/Postexample"> in HTML. My servlet is

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


public class Postexample extends HttpServlet {
 public void doPost(HttpServletRequest req,HttpServletResponse resp)
                    throws ServletException, IOException
{
   resp.setContentType("text/html");
   PrintWriter p=new PrintWriter(resp.getOutputStream());
   p.println("<html><body><h1>Hullo!</h1></body></html>");
   p.close();
}
}

It still comes up with the error "Connection reset by peer". I believe that this 
servlet runner came along with the jsdk2.1. That should mean that all people using 
this would have the same error  or that I have missed some patches. I also tried out 
the technique given in Jason Hunter's book 5 Th. chapter where instead of writing to 
the PrintWriter returned by getWriter(), the servlet first builds a 
ByteArrayOutputStream and then builds the PrintWriter around it. The advantage of this 
method is that we will be able to get the exact length of the output in bytes. The 
value that I have used in code that I had sent earlier sets the content length in 
characters.

If you have any more pointers on this , I would be grateful to receive them.

Regards
Mathew


>>> Nic Ferrier <[EMAIL PROTECTED]> 01/04/00 12:08PM >>>
>>> Matthew George <[EMAIL PROTECTED]> 04-Jan-00 3:45:19 PM >>>

>I tried the work arounds like writing the whole output to a
>StringBuffer and then writing the StringBuffer to the PrintWriter.
>I have used setContentLength() to the exact length of the
>output and also tried with  exact length plus two as someone
>suggested.

You should not set the content length if you are having trouble. The
easiest thing to do is try this:


void doPost(HttpServletRequest req,HttpServletResponse resp)
{
   resp.setContentType("text/html");
   PrintWriter p=new PrintWriter(resp.getOutputStream());
   p.println("<html><body><h1>Hullo!</h1></body></html>");
   p.close();
}


if that works then servletrunner is ok and it is your code.

Check that you are flushing and closing buffers properly.




Nic Ferrier

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to