• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception doesn't always cause flow to errorPage

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter,
thanks for your reply.
I increased the buffer size and I did get redirected to the error page.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic