?
Solved

JSP Multiple error pages required

Posted on 2003-03-06
25
Medium Priority
?
176 Views
Last Modified: 2010-03-31
Hi.
I have a number of tests in my JSP:
<%
    String student_no = (String)session.getAttribute("student_no");
    if(student_no==null)
         throw new StudentAppException("Missing session.student_no in index");
    StudentDetailsBean sBean = new StudentDetailsBean();
    if(sBean.getRecord(student_no)==null)
         throw new StudentAppException("Student not found in index");
%>
that currently throw the same exception:
  package usyd.orange.student.exceptions;
  public class StudentAppException extends java.lang.Exception {

, which opens up a defined error page, and displays an error message.
In my web.xml:
  <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/pages/errorPage.jsp</location>
  </error-page>

I need to have a seperate error page for each exception.

I was advised to try having a seperate exception:
  package usyd.orange.student.exceptions;
  public class StudentAppException1 extends java.lang.Exception {

for each one and throw as required (see the first throw has a new name):
In JSP:
<%
    String student_no = (String)session.getAttribute("student_no");
    if(student_no==null)
         throw new StudentAppException1("Missing session.student_no in index");
    StudentDetailsBean sBean = new StudentDetailsBean();
    if(sBean.getRecord(student_no)==null)
         throw new StudentAppException("Student not found in index");
%>
and then an extra lines in web.xml:
eg         <exception-type>packageName.className</exception-type>

  <error-page>
      <exception-type>java.lang.Exception.StudentAppException1</exception-type>
      <location>/pages/errorPage1.jsp</location>
  </error-page>
  <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/pages/errorPage.jsp</location>
  </error-page>
but not sure if syntax is correct for packageName.
do I use as above (it extends Exception doesnt it?)
or the full package name (usyd.orange.student.exceptions.StudentAppException1)

I have tried both ways but it always only displays the  errorPage.jsp and not the  errorPage1.jsp

I have also tried page errorPage="/pages/errorPage1.jsp"
which then uses the one page for all errors again.

Help please....
Again, my goal is to have a seperate JSP error page of each one I throw.



0
Comment
Question by:arobertson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 12
25 Comments
 
LVL 92

Accepted Solution

by:
objects earned 750 total points
ID: 8085968
should be:

<error-page>
     <exception-type>usyd.orange.student.exceptions.StudentAppException1</exception-type>
     <location>/pages/errorPage1.jsp</location>
 </error-page>
 
0
 
LVL 92

Expert Comment

by:objects
ID: 8085977
Or you can add the following to the top of your jsp to have a single handler for just that page:

<%@ errorPage="/pages/errorPage1.jsp" %>
0
 

Author Comment

by:arobertson
ID: 8086205
These answers dont help.
RE suggestion 1 ----------------
Using the full package name still does not give me errorPage1.jsp
If I comment out:
<!--
  <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/pages/errorPage.jsp</location>
  </error-page>
-->
and just leave in your suggestion, I get a a standard error page (not my pretty one)
eg HTTP Status 500 - Internal Server Error

And if I have both sections in (in either order):
  <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/pages/errorPage.jsp</location>
  </error-page>

  <error-page>
        <exception-type>usyd.orange.student.exceptions.StudentAppException1</exception-type>
        <location>/pages/errorPage1.jsp</location>
  </error-page>

I only get errorPage.jsp
RE suggestion 2 ----------------
<%@ errorPage="/pages/errorPage1.jsp" %>
Yes it gives me errorPage2, but for all errors on the page

But I have 2 'if' statements in the 1 JSP page that each throw a different exception, and I need them to display seperate error pages.

Thanks for the suggestions,
But I am still no closer to an answer.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 8086243
> and I need them to display seperate error pages.

Then you can't use the per page errorPage directive.

So specifying error pages for different exception type in web.xml is the way to go.
Not sure why it is not working. You say you get the 'standard' error page, is this the /page/errorPage.jsp? And what exception does it report has been thrown?
0
 
LVL 92

Expert Comment

by:objects
ID: 8086254
> , is this the /page/errorPage.jsp?

Ignore this question, I understand what you mean now.
Still like to know what exception it reports as being thrown.
0
 
LVL 92

Expert Comment

by:objects
ID: 8086261
You have a StudentAppException1 and a StudentAppException, have you added entries for both?
0
 

Author Comment

by:arobertson
ID: 8100337
Yes I have a StudentAppException1 and a StudentAppException
I have put in web.xml entries for both:
  <error-page>
        <exception-type>usyd.orange.student.exceptions.StudentAppException</exception-type>
        <location>/pages/errorPage.jsp</location>
  </error-page>
  <error-page>
        <exception-type>usyd.orange.student.exceptions.StudentAppException1</exception-type>
        <location>/pages/errorPage1.jsp</location>
  </error-page>

But I only see the default error page (black text on white page, with some headings inverse blue, not either of my errorPage's).

If I have this in as well I get errorPage.jsp
  <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>/pages/errorPage.jsp</location>
  </error-page>
and the exception it reports as being thrown is:
usyd.orange.student.exceptions.StudentAppException1

0
 
LVL 92

Expert Comment

by:objects
ID: 8100346
What container are you using?
0
 

Author Comment

by:arobertson
ID: 8100977
<web-app>
0
 
LVL 92

Expert Comment

by:objects
ID: 8101005
No what server software are you running and what version.
eg. tomcat, resin, weblogic
0
 

Author Comment

by:arobertson
ID: 8101038
Sorry,
Tomcat 4.1.10
0
 

Author Comment

by:arobertson
ID: 8101039
Sorry,
Tomcat 4.1.10
0
 

Author Comment

by:arobertson
ID: 8108949
Hi Objects,
I have not heard from you.
- probably just as busy as I am  :-)
Are you able to provide further assistance on this problem?

Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 8108963
sorry yes, trying to do too many things at once.
let me do a couple of tests here and I'll get abck 2u shortly.
0
 
LVL 92

Expert Comment

by:objects
ID: 8109032
0
 
LVL 92

Expert Comment

by:objects
ID: 8109080
Where in your web.xml do you put the error-page directive?

Try it in different places and see if you get different results.

Also check your log to see if it is getting parsed correctly.
0
 

Author Comment

by:arobertson
ID: 8114880
It is currently somewhere in the middle of the file.
I have moved it to the top and to the bottom, and no difference.

And the logs look OK to me. (see below)

I had a look at that bug you linked me to, and it does look similar, but I could not workout what they indicated the fix was.

Where to now?

----cut from log /usr/local/tomcat4110/logs/localhost_log.2003-03-12.txt
---------
2003-03-12 08:27:00 StandardHost[localhost]: Installing web application at context path /Student from URL file:/usr/local/tcprod/webapps/Student
2003-03-12 08:27:00 WebappLoader[/Student]: Deploying class repositories to work directory /usr/local/tomcat4110/work/Standalone/localhost/Student
2003-03-12 08:27:00 WebappLoader[/Student]: Deploy class files /WEB-INF/classes to /usr/local/tcprod/webapps/Student/WEB-INF/classes
2003-03-12 08:27:00 ContextConfig[/Student]: Added certificates -> request attribute Valve
2003-03-12 08:27:00 ContextConfig[/Student]: Configured an authenticator for method NONE
2003-03-12 08:27:00 StandardManager[/Student]: Seeding random number generator class java.security.SecureRandom
2003-03-12 08:27:00 StandardManager[/Student]: Seeding of random number generator has been completed
2003-03-12 08:27:00 Student: Start of AppInitialise::init()
2003-03-12 08:27:00 StandardWrapper[/Student:default]: Loading container servlet default
2003-03-12 08:27:00 StandardWrapper[/Student:invoker]: Loading container servlet invoker
----end cut-----

----cut from log /usr/local/tomcat4110/logs/apache_log.2003-03-12.txt---------
2003-03-12 08:27:01 WarpHost[<servername was here>]: Installing web application at context path /Student from URL file:/usr/local/tomcat4110/webapps/Student
2003-03-12 08:27:01 WebappLoader[/Student]: Deploying class repositories to work directory /usr/local/tomcat4110/work/Apache/<servername was here>/Student
2003-03-12 08:27:01 WebappLoader[/Student]: Deploy class files /WEB-INF/classes to /usr/local/tomcat4110/webapps/Student/WEB-INF/classes
2003-03-12 08:27:01 ContextConfig[/Student]: Configured an authenticator for method NONE
2003-03-12 08:27:01 StandardManager[/Student]: Seeding random number generator class java.security.SecureRandom
2003-03-12 08:27:01 StandardManager[/Student]: Seeding of random number generator has been completed
2003-03-12 08:27:01 Student: Start of AppInitialise::init()
2003-03-12 08:27:01 StandardWrapper[/Student:default]: Loading container servlet default
2003-03-12 08:27:01 StandardWrapper[/Student:invoker]: Loading container servlet invoker
---end cut----------
0
 
LVL 92

Expert Comment

by:objects
ID: 8115138
I don't see in the log where it is picking up the error-page entry?
0
 

Author Comment

by:arobertson
ID: 8115191
I could not see in the log where is was doing anything from the web.xml file.

Am I looking at the correct logs?
0
 
LVL 92

Expert Comment

by:objects
ID: 8115648
Sorry I meant the logging info that appears on console when tomcat starts up (not sure if it actually goes to a file).

I see entries like the following when I start up:

XmlMapper: new null org.apache.catalina.deploy.ErrorPage error-page ErrorPage[er
rorCode=0, location=null]
XmlMapper: org.apache.catalina.deploy.ErrorPage.setExceptionType( java.lang.Null
PointerException)
XmlMapper: org.apache.catalina.deploy.ErrorPage.setLocation( e1.jsp)
XmlMapper: Calling org.apache.catalina.core.StandardContext.addErrorPage ErrorPa
ge[exceptionType=java.lang.NullPointerException, location=e1.jsp]
XmlMapper: pop error-page org.apache.catalina.deploy.ErrorPage: ErrorPage[except
ionType=java.lang.NullPointerException, location=/e1.jsp]
XmlMapper: new null org.apache.catalina.deploy.ErrorPage error-page ErrorPage[er
rorCode=0, location=null]
XmlMapper: org.apache.catalina.deploy.ErrorPage.setExceptionType( objects.MyExce
ption1)
XmlMapper: org.apache.catalina.deploy.ErrorPage.setLocation( e2.jsp)
XmlMapper: Calling org.apache.catalina.core.StandardContext.addErrorPage ErrorPa
ge[exceptionType=objects.MyException1, location=e2.jsp]
XmlMapper: pop error-page org.apache.catalina.deploy.ErrorPage: ErrorPage[except
ionType=objects.MyException1, location=/e2.jsp]
XmlMapper: Debug level: 3
0
 

Author Comment

by:arobertson
ID: 8115849
I dont get these messages upon tomcat starting.

I have looked everywhere for a log file that has this stuff in it but can not find it.

Ill keep looking.
Can you find where it logs on your system?

Thanks
0
 

Author Comment

by:arobertson
ID: 8116022
What OS are you using?

We are running on RedHat 7.3

Maybe the output from starting the service is different?

all I see is:
------------
Using appVER = prod

Stopping Tomcat: Using CATALINA_BASE:   /usr/local/tcprod
Using CATALINA_HOME:   /usr/local/tcprod
Using CATALINA_TMPDIR: /usr/local/tcprod/temp
Using JAVA_HOME:       /usr/local/javaprod

Using appVER = prod

Starting Tomcat: Using CATALINA_BASE:   /usr/local/tcprod
Using CATALINA_HOME:   /usr/local/tcprod
Using CATALINA_TMPDIR: /usr/local/tcprod/temp
Using JAVA_HOME:       /usr/local/javaprod
----------------
0
 
LVL 92

Expert Comment

by:objects
ID: 8116212
i'm on w2k.
that script you are running, just kicks off another script.
let me do some more digging to see where the logging is going.
0
 

Author Comment

by:arobertson
ID: 8522521
Hi Objects
Sorry its been a while.

I ended up modifinging the one error JSP page to conditionally display what I want depending on which error class I threw.

I received the same advice from a different source as you originaly gave me, and they also could not understand why my system is not working correctly.

So Ill accept you original response as the answer so that you will get these points.

Again, Thanks for all the assistance.
Adam
0
 

Author Comment

by:arobertson
ID: 8522535
Thanks for the help!
It didnt work on my system, but others have given me the same suggestion.
Must be something else wrong with my system.

See my last comment re what I did end up doing.

Again Thanks
Adam
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question