File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception doesn't always cause flow to errorPage

 
Rob Chadwick
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am modifying a JSP (running on WebLogic Server 4.51).
I was making changes to add an errorPage (in the hope of making
debugging easier) and I tested it by adding a line of code that
would cause a DivideByZero exception:
<% int xyz = 1/0; %>
Sure enough, the error page displayed! So far, so good.
However, I found that if I moved the statement that causes the exception lower down in the document I wasn't getting an errorPage.
All I get is a partial document (HTML below the statement isn't
being processed).
I guess I need to look at the generated servlet code to work out why it's not forwarding to the errorPage, but I was wondering if
any one else had come across this problem and worked out the cause.

 
maha anna
Ranch Hand
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
Did you put those errorPage and isErrorPage attributes in your main.jsp and errorPage.jsp properly?
Please have a look at this example. http://www.javaranch.com/ubb/Forum7/HTML/002845.html
Just take this code and insert your divide By Zero code inside body tags and check.
regds
maha anna
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Chadwick:
However, I found that if I moved the statement that causes the exception lower down in the document I wasn't getting an errorPage.
All I get is a partial document (HTML below the statement isn't
being processed).

The problem is that the response has already been committed. The servlet engine uses an output buffer, which is 8KB by default. As soon as it is full, the first chunk of the HTTP response is sent to the client, including the HTTP header. Once the response has been committed in this way, the client simply cannot be redirected to the error page anymore.
That is what you are seeing: as you move your erroneous code down, you go past the point where the response is being committed. The exception thrown will prevent the remainder of the JSP from executing, so you end up with half a page.
There are two things you can do. The first and easiest is to increase the response buffer size (<%@page buffer="16kb"%> ). But, generally, you should try to do all the important processing before you start generating content in earnest.
- Peter
 
Rob Chadwick
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
thanks for your reply.
I increased the buffer size and I did get redirected to the error page.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic