A strange problem

2003-03-14 Thread V Y


Dear All:
I come across a very strange error and appreciate any help/tips.
My env:
  I am using Jakarta Tomcat 4.1.12 (on Linux) and 4.1.18 (on Solaris).
  I have installed MySQL JDBC connector and I have written
  some JSP code to input/retrieve data from my MySQL database.
  The MySQL DB is running on the Linux box.
  In my JSP code, I used a lot of these methods to get around
  between pages:
 RequestDispatcher dp = 
getServletContext().getRequestDispatcher("some path to a page");
dp.forward(request, response);

  At some other pages that does not have JSP, the standard HTTP post
  is used for going to the next page.
  I have also some backend Java code that sits in the
  shared/lib directory that my JSP code will interact with.
  I have worked on this for about a month and just this
  week, I came to notice this problem.
  A single operation involves 4 pages of fill-in-blanks on different
  forms.  I would go through one cycle (the 4 pages) once.  Redirect
  back to the beginning and if I would go through right away
  the same cycle, I would choke in between pages.  The browser is spinning 
after I press that "Continue" button and after a while
would display the standard "Page cannot be loaded" message.
  If I restart the servlet engine, everything is fine again for
  the first time and the cycle repeats.
  If I comment out the RequestDispatcher section above
  from a page that it was choking on, then it displayed that
  page just fine.

  Everything seems to point to the RequestDispatcher not able
  to actually forward to the next page.  Sometimes, those static
  HTTP post pages have the same problems too though not as consistent.
  Not sure what I did wrong.  I did not do any extra config and use
  Tomcat right out of the download.
  Any help/tip much appreciated

  --Vincent





_
MSN 8 with e-mail virus protection service: 2 months FREE*  
http://join.msn.com/?page=features/virus

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


Re: A strange problem

2003-03-14 Thread Paul Yunusov
On Friday 14 March 2003 01:55 pm, V Y wrote:
> Dear All:
> I come across a very strange error and appreciate any help/tips.
>
> My env:
>I am using Jakarta Tomcat 4.1.12 (on Linux) and 4.1.18 (on Solaris).
>I have installed MySQL JDBC connector and I have written
>some JSP code to input/retrieve data from my MySQL database.
>The MySQL DB is running on the Linux box.
>
>In my JSP code, I used a lot of these methods to get around
>between pages:
>
>   RequestDispatcher dp =
> getServletContext().getRequestDispatcher("some path to a page");
>  dp.forward(request, response);
>
>At some other pages that does not have JSP, the standard HTTP post
>is used for going to the next page.
>I have also some backend Java code that sits in the
>shared/lib directory that my JSP code will interact with.
>I have worked on this for about a month and just this
>week, I came to notice this problem.
>
>A single operation involves 4 pages of fill-in-blanks on different
>forms.  I would go through one cycle (the 4 pages) once.  Redirect
>back to the beginning and if I would go through right away
>the same cycle, I would choke in between pages.  The browser is spinning
> after I press that "Continue" button and after a while
> would display the standard "Page cannot be loaded" message.
>If I restart the servlet engine, everything is fine again for
>the first time and the cycle repeats.
>If I comment out the RequestDispatcher section above
>from a page that it was choking on, then it displayed that
>page just fine.
>
>Everything seems to point to the RequestDispatcher not able
>to actually forward to the next page.  Sometimes, those static
>HTTP post pages have the same problems too though not as consistent.
>
>Not sure what I did wrong.  I did not do any extra config and use
>Tomcat right out of the download.
>
>Any help/tip much appreciated
>
>
>--Vincent

The JSP page that forwards to the next one has its own response (the generated 
HTML) wiped out when the forward method is called because that's how the 
forward method works:

"forward should be called before the response has been committed to the client 
(before response body output has been flushed). If the response already has 
been committed, this method throws an IllegalStateException. Uncommitted 
output in the response buffer is automatically cleared before the forward."
(from the Servlet 2.3 API spec)

In general, using RequestDispatcher's forward method in a JSP page is 
ineffective because JSPs' purpose is to generate the final response (usually, 
HTML) and the RequestDispatcher's purpose is to delegate producing the 
response to another resource.

Try to use the RequestDispatcher's include method or one of the include tags 
to have several JSPs produce a single response (HTML) together. Remember, a 
JSP is just a template to generate HTML and using it for any other purpose 
such as coordinating workflows is an invitation for trouble. Introduce a 
controller servlet instead but discussing this is beyond the scope of this 
mailing list (as, in fact, all of the above but since Tomcat is a reference 
implementation of the Servlet/JSP spec, people close their eyes on this. They 
do, right?)

Paul

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