• 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

error page not found anymore.

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my web.xml I defined a dummy.jsp to handle error-code 400 (until a proper page is defined). This error page was being displayed as expected when I forced a 400 error code. Great!
When I pasted the following skeleton code into my dummy jsp (replacing the original code), my dummy page could no longer be found when I forced the error.
Is there something in this code that would cause the jsp to not be found?
<%-- Better (temporary) Error page --%>
<%@ page language="java" isErrorPage="true" %>
<%@ page import="java.io.PrintWriter" %>
<%@ taglib uri="/tags/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts/tags-html" prefix="html" %>
<%@ taglib uri="/tags/struts/tags-logic" prefix="logic" %>
<p></p>
<h2><bean:message key="label.error.heading"/></h2>


<logic:messagesPresent>
<ul>
<html:messages id="error">
<li><bean:write name="error" filter="false"/></li>
</html:messages>
</ul>
</logic:messagesPresent>
<pre>
<logic:notEmpty name="exception">

<%exception.printStackTrace(new java.io.PrintWriter(out));%>
</logic:notEmpty>

<logic resent name="javax.servlet.error.exception">
<% ((Exception)request.getAttribute("javax.servlet.error.exception")).printStackTrace(new PrintWriter(out)); %>
</logic resent>


</pre>

Thanks for any help,
Rich
 
author
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you are trying to use your error page for two purposes
1) As a standard error page according to servlet specifications
2) As a struts exception page as defined in struts-config.xml
By saying that the isErrorPage = true, you are trying to create the implicit exception variable.
But then by adding the html:messages, it looks like you are trying to use the page as a Struts exception page. In Struts exception page, there is no implicit exception variable since you dont need a isErrorPage = true at all!!
In Struts, before forwarding to the page indicated in the <exception> element, Struts sets the exception as a request attribute with name
org.apache.struts.action.EXCEPTION. (This is the value of Globals.EXCEPTION_KEY. Globals is a Java class in org.apache.struts
package). The exception can be retrieved in the error page by using the method: request.getAttribute(Globals.EXCEPTION_KEY).
So, it depends where the error is occuring in your code - In Struts or in the Servlet code. If you are trying to mix and match both mechanisms, then you are inviting trouble. Remove one of these based on how you want to use the error page
HTH.
Srikanth Shenoy
Author: Struts Survival Guide - Basics to Best Practices
 
Rich Smyth
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. I will junk the idea of trying to handle more than one type of error on the same page. However I don't think that the
"isErrorPage" attribute is at the root of my problem.
I'm dealing with a HTTP 400 error caused by trying to access an action for
which I do not have the correct role (as defined in strut-config).
Consider that my error page is displayed correctly if I define it like this: (very simple but it illustrates the problem):
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<table border="0" cellpadding="0" cellspacing="2" width="740" summary="Page Content">
<tr>
<td valign="top" >
<img src="<bean:message key="images.URL"/>/main_title_login.gif" width="91" height="21" border="0" alt="Login"><br>

<bean:message key="error.400"/>
<logic:present name="org.apache.struts.action.Globals.EXCEPTION_KEY">
DO NOTHING FOR NOW
</logic:present>
<html:form action="login" >
<%-- this form was left over from a cut/paste see note below--%>
</html:form>

</td>
</tr>
</table>
Now if I remove the <img> tag or if I remove the <html:form> tag above, the error page cannot be found when I trigger the error. The modified page can be displayed no problem via its URL. I'm trying to understand why this is happening.
Rich
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic