aspose file tools*
The moose likes JSP and the fly likes Displaying Error page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying Error page" Watch "Displaying Error page" New topic
Author

Displaying Error page

AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
Hi,

I got the error page working fine.

But if an exception happens in the middle of a page,
the top part displays the data till the exception occurs and then error page is also displayed.

Why isn't the error page only displayed?


Thanks
Anil
Anil
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

How did you declare your error page ?
Did you use the errorPage attribute in the page directive ?
Please tell us more.


[My Blog]
All roads lead to JavaRanch
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
In the normal pages i got

<%@ page import="java.sql.*,java.io.*,java.util.*" errorPage="error.jsp"%>

in the error.jsp i got

<%@ page import=" java.io.*" isErrorPage="true" %>

It works for some exceptions.

Thanks

Anil
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Ok.

the top part displays the data till the exception occurs

Can you please post the content of error.jsp ?
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
the content of the error.jsp

<body>
<h1></h1>
<p>
<table width="800" cellpadding="2" cellspacing="0">
<jsp:include page="header.jsp"/>
<tr>
<td colspan="3" valign="top"><div align="center"><font color="#333333" size="4" face="Verdana, Arial, Helvetica, sans-serif">
Error Page</font></div></td>
</tr>
</table><br>
<br>
<table><tr>
<td>Exception</td> <td><%= exception %></td>
</tr>
<tr><td>Message</td> <td><%= exception.getMessage() %></td></tr>
<tr><td>Stace trace</td>
<td><pre><% StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
out.println(sw); %> </pre></td></tr>
</table>


thanks
Anil
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Is the top part in header.jsp ?

You are using <jsp:include page="header.jsp"/> in your error page.
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
header.jsp just contains the the company logo, company heading and project name.

Anil
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Do you flush the output in the normal pages ? Like calling out.flush() ?
If so, this would explain why a part of the main page is displayed before the content of the error page.
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
I am not using any out.flush commands
Just normal html and jsp tags to display tables etc.

Thanks

Anil
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
What server are you using? I have seen this happen on JRun4, but never with Tomcat.

Like Satou seems to be getting at, I think the issue is caused because the page is flushed before the error occurs. Once the output is flushed/committed it is impossible to pull it back.
Is it a very big page? Would the page buffer have overflowed and forced a flush by the time the exception is raised?

Try putting this on your page, and seeing if the same still happens:
<%@ page buffer="32kb" %>
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
Thanks

I think that is the reason. It is a big page. I am using Tomcat.

Thanks

Anil
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Error page