tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anthony Presley <>
Subject response.reset() and forward() ... problematic? DBCP related?
Date Wed, 10 Dec 2003 23:43:49 GMT
Hi all,

Decided to move my discussion from Commons to Tomcat, as the
bug-tracking process appears that this is a more relevant place to post.

I'm not using a MVC implementation (ala Struts), but I do have about
100K lines of servlets and JSP's, and I'm having a lot of errors, which
scale based on the number of users.  For instance, assuming I have
around 10 people working on the system, I will have no errors.  As that
number scales, it becomes a huge problem, and lots of error's start
showing up.  I've tracked down and squashed most of the DB errors, but
am left with the following quandry:

I'm not storing any data in the session, and use forward() ... a lot. 
When the following code executes, and I only open one request (ie, I
click on the link to open a new window which fetches a servlet
response), it works flawlessly.  When I click more than once, I start
getting forward() errors.

Here's some code snippets:

  protected void forward(String s) {
      ServletConfig sc = null;
      ServletContext sContext = null;
      RequestDispatcher rd = null;
      try {
        sc = this.getServletConfig();
      } catch (Exception e) {
        log("2ERROR Exception: " + e.getMessage());
      try {
        sContext = sc.getServletContext();
      } catch (Exception e) {
        log("3ERROR Exception: " + e.getMessage());
      try {
        rd = sContext.getRequestDispatcher(s);
      } catch (Exception e) {
        log("4ERROR Exception: " + e.getMessage());
      try {
        log ("Buffer size is: " + res.getBufferSize());    
        if (rd != null)
          rd.forward(req, res);
        else {
          log("RD is NULL, MAJOR ERROR");
      } catch (ServletException e) {
        log("5ERROR ServletException: " + e.getMessage());
      } catch ( e) {
        log("5ERROR " + e.getMessage());
      } catch (Exception e) {
        log("5ERROR Exception: " + e.getMessage());

I will get an error "5ERROR ServletException: Cannot forward after
response has been committed".

This error is generated when the following conditions exist:

1.  More than one user is trying to pull the same information.  For
instance, if I open three windows, each requesting the same info, two of
them will likely error.  With twenty requests, I get about sixteen
errors [consistently].

2.  More than one user trying to pull different information.  Although
the error is almost certain to happen when more than one user pulls the
same data, pulling different data (simulated with multiple windows),
gets me the same error, at about the same frequency.

2.  Rerequesting the error'd page will get me the correct output (no
changes made to the data or JSP / servlets).  <IE, I'm not forwarding
twice, nor am I printing the buffer before I should [below]>

3.  I've bumped the response buffer (in the servlet) from 8K to 75K
(75000), which reduces the errors, but they are still present.  Is there
a GOOD way to estimate the amount needed?

4.  Using DBCP 1.0 .... using the latest DBCP (1.1?), seems to reduce
the errors further (1 in 10, approx).  I've rewritten the code to ensure
that connections are being opened / closed locally, and quickly.  Timing
it shows that the DB connection is pulled from the pool for about 2300
milli, and the JSP runs for about 2 milli to display.

I'm not 100% sure yet if the problem persists in the JSP (using a simple
JSP and simple servlet does not cause these problems, however, the
greater the complexity, the higher the likelihood of getting these
errors .... which baffle's me, because rerequesting it shows up fine,
with nothing in the logs) or the servlet.

Anyone seen this before?  I'm about at my wits end.  Been refactoring
for a week now, and still it persists.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message