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.
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
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
Joined: Mar 02, 2001
Peter, thanks for your reply. I increased the buffer size and I did get redirected to the error page.