Problem accessing exception object in jsp error page - Apache Tomcat 5.0.25

Hi all,
I'm thoroughly confused and need some help. I've deployed a very simple web application in Apache Tomcat 5.0.25 to test exception handling - errortest.jsp and error.jsp. errortest.jsp throws a divide by zero exception if executed with default values in text fields.
When I put the directive IsErrorPage="true" in error.jsp i get a HTTP 500 error when error.jsp is accessed. If I remove it error.jsp is displayed but I cant access the exception object - if I try to I get an exception below:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 5 in the jsp file: /error.jsp
Generated servlet error:
[javac] Compiling 1 source file
E:\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\mywebapp\org\apache\jsp\error_jsp.java:46: cannot resolve symbol
symbol : variable exception
location: class org.apache.jsp.error_jsp
out.print(exception.getMessage());
^
1 error
Below is the code for the two jsp pages:
errortest.jsp:
<%@ page errorPage="error.jsp" %>
<html>
<head><title>Error test</title></head>
<body>     
     <form action="errortest.jsp" method="post">
     Enter first number:<input type="text" name="first" value="5"/><br>
     Enter second number:<input type="text" name="second" value="0"/><br>
     <input type="submit"/>
     </form>
     <%
     if (request.getMethod().equals("POST")) {
          int first = Integer.parseInt( request.getParameter( "first" ) );
          int second = Integer.parseInt( request.getParameter( "second" ) );
          int answer = first/second;
     %>
</body>
</html>
NB: I am able to catch and display the exception if I use a try/catch block around the division as shown below.
try {
int answer = first/second;
} catch( Exception e) {
e.printStackTrace( new PrintWriter(out) );
error.jsp (first draft)
NB: HTTP 500 error occurs when directive "isErrorPage" is added:
<%@ page isErrorPage="true" %>
<html>
<head><title>Error Page</title></head>
<body>
</body>
</html>
error.jsp (second draft)
NB: directive is removed but exception thrown when implicit exception object is accessed. error.jsp displays if exception object is not accessed:
<%@ page %>
<html>
<head><title>Error Page</title></head>
<body>
<%=exception.getMessage()%>
</body>
</html>
Web server specs:
Apache Tomcat 5.0.25
Machine specs:
Windows XP Pro
Java environments:
j2sdk1.4.2_03
J2EE 1.4

This works for me:
throwError.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" errorPage="/error.jsp"
contentType="text/html; charset=utf-8" %>
<html>
<head>
     <title>Throw Exception</title>
</head>
<body>
Throwing exception....
<%
// throw ArithmeticException
int badInt = 12/0;
%>
</body>
</html>
error.jsp
<%@ page language="java" isErrorPage="true" %>
<head><title>Doh!</title></head>
An Error has occurred in this application.
<% if (exception != null) { %>
<pre><% exception.printStackTrace(new java.io.PrintWriter(out)); %></pre>
<% } else { %>
Please check your log files for further information.
<% } %>

Similar Messages

  • Displaying JSP error page in tomcat 5.5.7

    I'm using tomcat 5.5.7 with JDK1.4.1. I've created these 2 JSPs:
    index.jsp:
    <html>
    <title>Jsp</title>
    <body>
    <%@page errorPage="/error.jsp"%>
    Trying to write some error
    <% String butt = request.getParameter("butt");
    if (butt!=null )
       int p = 4/0;
    }%>
    <form method="post">
    <input type="submit" name="butt" value="head">
    </form></body></html> error.jsp:
    <html>
    <title>Jsp</title>
    <body>
    <%@ page isErrorPage="true" %>
    Error Body
    </body></html> When I run this JSP, and try to get the error page, I get internal
    server error page, insteaof of error.jsp.
    The error_jsp.java file has the following lines:
    Throwable exception =
    org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable
    (request);
    if (exception != null) {
    response.setStatus
    (HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } I tried to run these same files in Tomcat 4.1, and they work fine.
    What my be the problem? How can I have my error page be displayed?

    Hi,
    I do use Tomcat with the compatibility package (jmx.jar under $CATALINA_HOME/bin and xercesImpl.jar under $CATALINA_HOME/common/endorsed).
    I've put a System.out.println in the error.jsp, and it was printed to the stdout.log.
    Nothing else was printed to the log.
    I also tried removing the isErrorPage="true" from the error page, and I got it displayed (when the error occured). But of course that way I would not have any exception object....

  • JSP error page does not displayed on its own, includes in the original JSP

    Problem Description: - Exceptions in a Condition cause pages to fail to render.
    The actual issue is, the JSP error page does not displayed on its own, included in the original JSP Page when exception occurs.
    Problem Cause: As per the JSP specification when jsp content reached the buffer size (default 8KB) the page being flushed (Part of condent displays). The default �autoFlush� value is true.
    When the page buffer value is default size (8KB), and if any exception occurs after flushing the part of the content, instead of redirecting into error page, the error page content included in the original page.
    If i specify autoFlush="false" and with default buffer size, at the runtime if the buffer size is reached, i am getting stackoverflow error.
    To solve the above problem we can make it autoFlush=�false� and buffer=�100KB�. But we can�t predict the actual size of the page.
    I found in one of the weblogic forum as no solution for this issue. Ref.
    http://support.bea.com/application?namespace=askbea&origin=ask_bea_answer.jsp&event=link.view_answer_page_clfydoc&answerpage=solution&page=wls/S-10309.htm
    Please provide me any solution to resolve the problem.

    Error-Page tags work best with an error.html pages. If you have an error.jsp page what I would do, and I have, is wrap my classes and jsp pages in a try catch block where you forward to the error jsp page and display anything you want. YOu can also do this with if else statements. I have used the tomcat error pages before but when I've implemented them I used java.lang.Exception as the error to catch not Throwable. I don't know if this would make a difference or have anything to do with your problem.

  • JSP error page in web.xml

    I had a JSP error page spcified through the attribute isErrorPage and referenced in the other JSPs through the errorPage attribute, and everything worked well.
    Then, I decided to specify that errorpage in the web.xml instead :
    <error-page>
      <exception-type>java.lang.Throwable</exception-type>
       <location>/error.jsp<location>
    </error-page>The page is found and everythiing, except that I don't get the Throwable info in the implicit exception object in error.jsp. There's nothing in exception.getMessage().
    Anybody knows why and the solution to this ?

    The JSP spec lets you get the Throwable through the javax.servlet.jsp.jspException request attribute.
    The servlet spec uses the javax.servlet.error.exception request attribute for the same thing.
    Therefore, because of the above unfortunate mismatch, when you switched to a global error page, you could no longer get the Throwable through the implicit exception obj, because the later retrieves Throwable from the javax.servlet.jsp.jspException request attribute.
    The solution would be to retrieve javax.servlet.error.exception from the request yourself in your error page.

  • Problem accessing an object in a VBox

    Hi!
    I have a problem accessing an object which is in a VBox.
    I made an example so you can see my problem. I am trying to
    access pnlChat.
    If you load the swf you won't see the Alert because there is
    something wrong (and I don't know what)
    If you try to remove the <mx:VBox> tags that wrap the
    pnlChat Panel, it will work.
    Why can't I access this object when it is in a VBox?
    Thanks

    "Jimmy Jeeves" <[email protected]> wrote in
    message
    news:g8jv84$5ib$[email protected]..
    > Hi!
    >
    > I have a problem accessing an object which is in a VBox.
    > I made an example so you can see my problem. I am trying
    to access
    > pnlChat.
    > If you load the swf you won't see the Alert because
    there is something
    > wrong
    > (and I don't know what)
    > If you try to remove the <mx:VBox> tags that wrap
    the pnlChat Panel, it
    > will
    > work.
    >
    > Why can't I access this object when it is in a VBox?
    From the FAQ I'm compiling:
    Q: I need to set a property or add an event listener on a
    component
    that is in a ViewStack/TabNavigator/Accordion. When the
    component is not
    the first child of the Navigator Container, I get a null
    object error
    (#1009). What causes this, and how can I fix it?
    A: By default, the Navigator containers only create the
    children of
    each pane as that pane is viewed. The easy way to fix this is
    to set the
    creationPolicy on the Navigator to "all." However, this will
    cause your
    application to take longer to load. A better way to fix this
    is to wait for
    a later event, such as creationComplete on the component you
    want to access,
    or to use binding to "pull" the data into the component.
    The way I handle it is to call invalidateProperties() on
    change of the
    ViewStack. I then override commitProperties() and call an
    "initializer" for
    each pane. In the body of each initializer function, I check
    to see if the
    selectedItem for the viewStack is the one my initalizer cares
    about. If
    not, I return from the function immediately. Inside that
    initializer
    function, I set properties and add listeners as appropriate.

  • Referrer to JSP Error Page???

    I curious if anyone knows how I can programmatically find out the name of the page that triggered the JSP error page on the actual error page. Your assistance is much appreciated.

    Thank you all very much for your quick, intelligent replies! I gave babella 2 dollars for the first response in what I thought was the best solution for what I needed (although the response object storing could definitely be useful for other things as well), and the rest 1. This is my first time doling out dollars, so please let me know if I broke any ettiquette rules. Thanks again!

  • Get response message in JSP error page

    Hi,
    Here's a simple one for someone. I HAVE been searching everywhere for the answer but its one of those things I just cant seem to find.
    If I call response.sendError(SC_FORBIDDEN, "Invalid roles"); from a servlet or filter, how can I retrieve the message "Invalid roles" in my JSP error page? (which I have mapped to 403 errors in web.xml).
    Its so simple yet I cannot figure out how to do it.
    Thanks in advance,
    Robert.

    I tried but had no luck. Below is my JSPDYNPAGE code...
    <%@ page import="javax.servlet.http.HttpServletResponse" %>
    <%@ page import="com.sapportals.portal.prt.component.IPortalComponentRequest,com.sapportals.portal.prt.component.IPortalComponentResponse"%>
    <HTML>
         <head>
         </head>
         <body>
    <%
    IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
    HttpServletResponse servletResponse = request.getServletResponse(true);esss
    servletResponse.setStatus(500);
    %>
              </body>
         </HTML>
    It is not working showing portal run time error

  • How to access COM+ Objects From JSP

    Friends,
    We have a requirement to access COM+ objects from JSP. Please guide me on this.
    Thanks in advance.
    Tarani

    Sanyam wrote:
    if there is any .dll extension file, how can we read that file in labview?
    You can use Call Library Function node to call that dll file and use it in LabVIEW. Read the help and you will get more details.

  • Handle exception on server side and display a customized jsp error page

    Hi,
    I am developing a java/j2EE web application using servlet, jsp, ejb3 with JBOSS and ECLIPSE.
    Two cases can occur on the server side :
    1) either I have not an expected result in a method and in this case I want to display an error page (a JSP page I suppose) with a personnalized error message
    2) or I have an exception thrown and I want to display the exception message in the former JSP page
    I don't know how to cope with this problem of personnalized error message (or the message of a thrown exception) with a JSP page.
    Does anybody can help me ? Thank you
    Edited by: xflamant on Jun 20, 2009 10:51 AM

    For the case of an unknown Error, simply use a default error page.
    The redirection to this page can be accomplished by inserting folowing code into your web.xml:
         <error-page>
            <exception-type>java.lang.Throwable</exception-type>
            <location>/WEB-INF/jsp/error.jsp</location>       
        </error-page>Known exception can be caught via a try-catch block.
    Then simply dispatch to the page you want displayed an add an attribute containing the error message to the response object.
    This attribute can then be used in the target page to diplay the error.

  • Problem in Jsp Error page mechanism

    Hi every body,
    In my Jsp application I do some processing within scriplet tags. I have defined a error page using a page directive and I have defined my Error page separately. When there is an exception in a Jsp page, some times it calls the error page properly and displays it. But curiously in some occasions when there is an exception it doesn't call the error page, instead it includes the content of the Error page at the end of the same page, where the exception occurred. The web server is jakarta-tomcat-3.2.1. Can any one who has a idea about this problem help me. Your help is greatly appreciated.
    Thank you

    Hi there!
    Well I was having the same problem as yours until I realized what was going on: the jsp writer has a small buffer size (by default 8kb) and that is why it flushes some html before displaying the error page. The jsp writer buffer is full before getting the exception, so it flushes the buffer and keeps on writing until the exception is thrown. Then the jsp writer writes the error page code...
    You have to add some new parameters in your page directive: autoFlush(true or false) and buffer="16kb" (as much kbytes as you want). For example,
    <%@page autoFlush="false" buffer="sizekb".... %>
    If autoFlush="false", the jsp writer has not finished and the buffer is full an exception will be thrown.
    If autoFlush="true" and the buffer is full it will flush the buffer and so on.
    In both cases, if the buffer size is big enough the error jsp page will be the only displayed
    Good luck!
    Inaki

  • Problems with jsp-error page in web.xml

    Hello everybody, I have a confusing problem concerning the use of jsps as error pages for 404-errors.
    I inserted the following lines in my web.xml file:
    <error-page>
    <error-code>404</error-code>
    <location>/personal404.jsp</location>
    </error-page>
    The problem is: when an 404 occurs, instead of showin the personal404.jsp, the browser tells me that it tries to download a file which it can't (it tries to download the mis-spelled file). When I try to redirect the 404 to a static html-page, as in
    <error-page>
    <error-code>404</error-code>
    <location>/personal404.html</location>
    </error-page>
    everything works fine.
    Please, does anybody have any idea or suggestion, what I am doing wrong?
    Thanks in advance,
    Sebastian

    Hi Ivan,
    I tried it, but there wasn't any difference.
    I'll try to explain in more detail what happens:
    Imagine my application has the following root-path
    http://myServerName:port/mainRoot/
    When I try the following URL:
    http://myServerName:port/mainRoot/pageThatDoesNotExist.jsp, the browser tells me, it tries to download the file pageThatDoesNotExist.jsp from myServerName and that it can't find that file.
    The same happens, when I type http://myServerName:port/mainRoot/pathThatDoesNotExist/pageThatDOESExist.jsp, except that the browser tries to download the file pageThatDOESExist.jsp which (again) it can't.
    I have located the files 404.jsp and 404.html in the same directory, so I don't think this is a path-related problem, because everything works fine, when I specify the 404.html as the target error page (i.e. the browser displays the 404.html when I type the URLs shown above).
    I don't know if I'm making this clear, but maybe you get the idea.
    Sebastian

  • Problem accessing oracle databse with JSP

    hI
    i'M TRYING TO ACCESS A ORACLE 8I DATABASE VIA A JSP. THE DATABASE IS LOCATED REMOTELY ON THE NETWORK AND I' USING JDEVELOPER 9i VERSION 9.0.3.1
    wHEN I RUN MY JSP, I WANT IT TO DISPLAY THE RESULT OF A QUERY ON MY JSP PAGE but instead i get this error on my error page : java.lang.NullPointerException
    what do u think is wrong with my code
    here it is :
    <%@ page language="java" %>
    <%@ page import = "java.sql.*" %>
    <%@ page import = "java.io.*" %>
    <%@ page errorPage="errorpage.jsp" %>
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%
    String uname= request.getParameter("username");
    String pword= request.getParameter("password") ;
    String driverName = "oracle.jdbc.driver.OracleDriver" ;
    String dbUrl = "jdbc:oracle:thin:136.150.11.3:1521:orcl" ;
    /*String user = "hr8" ;
    String pass = "password" ; */
    Connection con= null ;
    Statement stmt = null;
         ResultSet rs = null;
    try
    { //loading driver
    Class.forName(driverName);
    catch (ClassNotFoundException e) {
    out.println("Unable to load driver class");
    try // connecting to the database
    con = DriverManager.getConnection(dbUrl,uname,pword);
    catch(SQLException ex){
    out.println("Error while connecting to the Database :" +
    ""+ ex.toString() );
    // create query
    stmt = con.createStatement();
    rs = stmt.executeQuery("select COUNTRY_NAME ,REGION_ID " +
    "from COUNTRIES where REGION_ID in (1,3,5,7,9);");
    while (rs.next())
    out.println(rs.getString(1));
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>
    LOGIN UNITRANSFER
    </title>
    </head>
    <body>
    <h2>
    I got it
    <%
    out.println(uname);
    %>
    </h2>
    <p>
    </body>
    </html>

    The dbUrl should be of the format:
    "jdbc:oracle:thin@" + serverName + ":" + serverPort
    + ":" + dataBaseSID;
    String dbUrl = "jdbc:oracle:thin:@136.150.11.3:1521:orcl";

  • Details on JSP error page include...

    I have a scenario as defined below:-
    There are two JSPs, A_page.jsp and B_page.jsp.
    They have AERROR.jsp and BERROR.jsp defined as error pages for them respectively.
    Case1:- If A_page.jsp includes B_page.jsp using include directive.
    In case there is an error, which error page will be shown, AERROR.jsp or BERROR.jsp?
    Case2:- If A_page.jsp includes B_page.jsp using JSP action.
    In case there is an error, which error page will be shown, AERROR.jsp or BERROR.jsp?
    Please clarify...
    Thanks in advance... ;-)

    call.jsp
    <%@page errorPage="first.jsp" %>
    <%=1/0%>
    first.jsp
    <%@page isErrorPage="true" %>
    <%="errorfirst"%>
    <%@include file="second.jsp" %>
    second.jsp
    <%@page isErrorPage="true" %>
    <%="errorSecond"%>
    output
    errorfirst errorSecond
    (so it will display all first and second error jsp`s)...
    its like a sub call (or) inline call in c++...
    and vice versa

  • I don't understand the following error on apache tomcat

    Good afternoon!
    I am using tomcat 6.0.13.When i try to perform my servlet, the following exception is gone off :
    exception
    javax.servlet.ServletException: Error allocating a servlet instance
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    java.lang.Thread.run(Thread.java:595)
    root cause
    java.lang.NoClassDefFoundError: mypackage/Transportadora (wrong name: Transportadora)
    java.lang.ClassLoader.defineClass1(Native Method)
    java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1817)
    org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    java.lang.Thread.run(Thread.java:595)
    Would be this a problem in the definition of the class?
    web.xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
    <display-name>Transportadora </display-name>
    <description>
    Projeto Transportadora
    </description>
    <servlet>
    <servlet-name>Transportadora</servlet-name>
    <servlet-class>mypackage.Transportadora</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Transportadora</servlet-name>
    <url-pattern>/transp</url-pattern>
    </servlet-mapping>
    </web-app>
    A great one I hug and grateful for the attention!
    Message was edited by:
    tarssa
    Message was edited by:
    tarssa
    Message was edited by:
    tarssa

    java.lang.NoClassDefFoundError: mypackage/Transportadora (wrong name: Transportadora) You need to make sure all your classes are in the classpath and/or you need to make sure you're calling the class by its correct name.

  • How to run jsp file in Apache Tomcat 5.0?

    hi,
    i'm using jdk1.5,jsp1.2 & Apache Tomcat 5.0 as a web server.in my application i have 2 jsp files,1 html file & 1 javabean class.where i must place the html,jsp files and the .java file & .class file for a bean class.how to run this application.
    bean class:
    public class Userdata {
    private String username;
    private String email;
    private int age;
    public void setUsername( String value )
    username = value;
    public void setEmail( String value )
    email = value;
    public void setAge( int value )
    age = value;
    public String getUsername() { return username; }
    public String getEmail() { return email; }
    public int getAge() { return age; }
    getname.html file:
    <HTML>
    <BODY>
    <FORM METHOD=POST ACTION="Savename.jsp">
    What's your name? <INPUT TYPE=TEXT NAME=username SIZE=20><BR>
    What's your e-mail address? <INPUT TYPE=TEXT NAME=email SIZE=20><BR>
    What's your age? <INPUT TYPE=TEXT NAME=age SIZE=4>
    <P><INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>
    savename.jsp file:
    <jsp:useBean id="user" class="Userdata" scope="session"/>
    <jsp:setProperty name="user" property="*"/>
    <HTML>
    <BODY>
    Continue
    </BODY>
    </HTML>
    nextpage.jsp file:
    <jsp:useBean id="user" class="Userdata" scope="session"/>
    <HTML>
    <BODY>
    You entered<BR>
    Name: <%= user.getUsername() %><BR>
    Email: <%= user.getEmail() %><BR>
    Age: <%= user.getAge() %><BR>
    </BODY>
    </HTML>
    refer these source code and plz,give the result at the earliest.
    whether i want to write a web.xml file for this jsp file.
    if yes,means plz present the web.xml file for this application.
    plz,if anybody knows give me detailed description for this application.

    create a dir under webapps dir
    place your .html and .jsp files here
    also create WEB-INF dir here
    Under WEB-INF create classes and lib dir
    under classes dir put your .class file
    You also need to put web.xml under your WEB-INF dir.
    You ca keep your java file any where u want on your computer.

Maybe you are looking for

  • WAAS: WCCP Mask or Hash on Routers?

    I'm starting thinking about using mask assign on an ISR router running 12:4(24)T with GRE/GRE. Has anyone done this before and can you use mask assign with GRE/GRE? We need to use it with GRE/GRE because our egress method has to be WCCP return. My th

  • Advantages of opensolaris or developer edition?

    Hi, noob question. So far I have been using SunStudio12 on Ubuntu 7.04-8.04 with no problems. Now I got my hands on OpenSolaris and SolarisExpress DEveloper edition's DVDs. Are there any fundamental advantages of migrating to either of this OSes in t

  • Radeon card keeps losing signal in games in 8x AGP mode.

    I have a problem with my boardand i was wondering if anyone else had the same problem. i have a MSI K8t Neo2 Athlon 64 3500+ (Venice) Radeon x850xt PE 1 gig ddr 3200 ram in dual channel In 3d applications my monitor looses signal so i thin ktis a gra

  • Can't export/share project. share halts/freezes at 5%

    My version of final cut pro does not have a share tab at the top thus I have to share > master file through the file tab. Each time I attempt to share it only reaches 5% complete before freezing. I have attempted many different variables and am think

  • Network Start Up Drives

    I have some networked drives being started at logon, all that is working great, but is there a way so they don't open in their own Finder folder? I have to manually close each folder when I reboot and it's kind of a pain. Thanks.