That's what the problem is and I have changed it already. Anyhow thanks for
your help. Thanks for all.
Regards,
Kumar
-----Original Message-----
From: Kevin Mukhar <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Wednesday, December 01, 1999 9:20 PM
Subject: Re: Response while multiple hits
Kumaravadivelu wrote:
>
> Hi,
> I have a problem in getting response from the servlet when I call the
> servlet simultaneously from different browsers/browser windows. The
problem
> is if I call the servlet from two browsers, one shows the response page
> where as the second one show me an error 'document contains no data', can
> anyone please let me know why am getting this error?
>
> I am adding a piece of code here.
>
> public void doPost(HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException
> {
>
> res.setContentType("text/html");
> out=res.getOutputStream();
>
> try {
> <codes for database manipulation>
> } catch (Exception e) {}
>
> out.println("<html><head><title>Testing</title></head><body>");
> out.println("<center>");
> out.println("<h2>Your data has been accepted</h2>");
> out.println("</center>");
> out.println("</body></html>");
> out.close();
> }
The problem is that you are using what appear to be instance variables in
this
method. Since the servlet engine will send multiple requests into the class,
the
instance variables get changed by each thread.
Specifically there is a problem with your use of the variable out. Since it
is
not defined inside the method, it appears to be an instance variable. When
multiple threads enter this method concurrently, each thread changes the
value
of out. Thus or more of the responses will be messed up.
The other problem, as others have pointed out, could be in your database
manipulation. Again, you need to make sure each thread will get its own
connection to the database, and that the resultSet returned is not going to
be
changed by another thread.
See the Servlet FAQ for more information on threads:
http://www.purpletech.com/servlet-faq/
Kevin Mukhar
___________________________________________________________________________
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