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

Similar Messages

  • 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

  • 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.

  • 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

  • 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.

  • 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!

  • 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.
    <% } %>

  • 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.

  • 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....

  • 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

  • Problem displaying error page of web.xml when using JSF, Ajax4jsf

    Hi,
    My application is using MyFaces, RichFaces and Ajax4jsf. When i try to display error page configured in web.xml, i am getting exception "Error while processing error page".
    my web.xml contents are as follows:
    <?xml version="1.0"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="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">
    <filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>faces</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <filter>
    <filter-name>extensionsFilter</filter-name>
    <filter-class>
    org.apache.myfaces.webapp.filter.ExtensionsFilter
    </filter-class>
    <init-param>
    <description>
    set the size limit for uploaded files. Format: 10 - 10 bytes 10k
    - 10 KB 10m - 10 MB 1g - 1 GB
    </description>
    <param-name>uploadMaxFileSize</param-name>
    <param-value>100m</param-value>
    </init-param>
    <init-param>
    <description>
    Set the threshold size - files below this limit are stored in
    memory, files above this limit are stored on disk.
    Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
    </description>
    <param-name>uploadThresholdSize</param-name>
    <param-value>100k</param-value>
    </init-param>
    </filter>
    <filter>
    <filter-name>Seam Redirect Filter</filter-name>
    <filter-class>org.jboss.seam.servlet.SeamRedirectFilter</filter-class>
    </filter>
    <filter>
    <filter-name>KTServletFilter</filter-name>
    <filter-class>com.kenexa.core.system.KTServletFilter</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>Seam Redirect Filter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <filter-mapping>
    <filter-name>KTServletFilter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>
    <!-- seam Listeners -->
    <listener>
    <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
    </listener>
    <listener>
    <listener-class>com.kenexa.kr.web.KRServletListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>faces</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>faces</servlet-name>
    <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/rc/systemError.jsf</location>
    </error-page>
    </web-app>
    As per the configuration, when exception is thrown out of the application, container tries to display systemError.jsp page. If we want to include the JSF tags in systemError.jsp page, the request should pass through FacesServlet, so in the <error-page> <location> tag systemError page is specified with the extention systemError.jsf though it's actual extention is .jsp
    When exception is thrown from the application container invoke the error page but, while rendering systemError.jsf page exception is thrown saying "Exception processing error page "systemError.jsp" "
    To solve this problem i've gone through several forums, materials.
    In one forum a guy said, JSF1.1 spec has some problem in displaying error pages. To solve this don't write <f:view> tags in the error page, use <f:subview> intstead. By reading this, i again changed the contents of systemError.jsp page replacing <f:view> by <f:subview>. But the error is still repeating.
    Finally what i found is, when we use Ajax4jsf in the application, its AjaxViewRender class is throwing exception while rendering error pages configured through web.xml.
    So what i did is i changed error page extention from .jsf to .jsp in the <location> tag. Now jsf won't come in the picture and remove JSF related tags from the systemError.jsp page.
    <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/rc/systemError.jsp</location>
    </error-page>
    Any comments are welcome----------------------------------------------------------------

    I too iam facing the same problem could you advise if you have found any solutions
              -Ram

  • No error page after runtime include

    Hi
    I encountered the problem that my error-page is not displayed when a runtime-exception occures in a jsp.page after having made a runtime-include of another jsp-page
    (like <jsp:include page='../rt_includes/header.jsp' flush='true' />).
    If I take away the include-statement, the error page is displayed correctly. The problem seems to be that printing the content of the included page to the out-buffer prevents the error page to be displayed properly. Which is the best solution to avoid this problem?
    - Thanks for any help

    Hi,
    The problem you have just described comes in JSP 1.3 specification. This problem was solved in JSP 1.4 specification, Most of the application server now support JSP 1.4, check out with your application server documents. Which server are you using.

  • How can we define custom error page in protal application

    How can we define custom error page in protal application, like we define "jsp Error page " in JSPs

    Hi,
    Check these:
    Customization of Portal Runtime Errors and portal standard error codes
    http://help.sap.com/saphelp_nw04/helpdata/en/9a/e74d426332bd30e10000000a155106/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/ec/1273b2c413b2449e554eb7b910bce7/frameset.htm
    Regards,
    Praveen Gudapati

  • How to display a stack trace in a jsp error mage

    What is the best way to display a stack trace in a JSP error page?
    I use "${pageContext.exception.message}" for the exception message. Is there a comparable JSTL expression for the stack?

    Cool! it totally works.
    Thanks for pointing me to this post.

  • Tomcat error pages

    How can i define my own jsp error pages, and how do i suse them after defining them?
    thanks

    errorPage attribute specifies a JSP page that should process exceptions that are thrown but not caught by the current page.
    <% page errorPage="Relative URL" %>
    There is also the isErrorPage attribute.
    This indicates whether or not the current page can act as an error page for another JSP page.
    <% page isErrorPage="true" %>
    <% page isErrorPage="false" %><%-- this is the default --%>
    Sooooo as an example...
    You are in a JSP page and an error is generated. You have indicated already that if an error is generated oin this page you should go to the Error JSP page.
    --- Inside of "someCalculation.jsp" ---
    <% page errorPage="iamTheJSPErrorPage.jsp" %>
    --- Inside of "iamTheJSPErrorPage.jsp" ---
    <% page isErrorPage="true" %>
    Remember that these are relative URLs that are requried. So if you have your Error page in another directory, you must reflect that in your URL.
    Hope that helps

Maybe you are looking for

  • Can't make a ringtone

    i bought a song a little over a week ago off itunes and it had the ringtone bell icon next to it. it still has the ringtone icon, but when i click it to try and make a ringtone it says the song can no longer be made into a ringtone. i looked it up ag

  • (P/S & Bridge) CS 5.5 (5.1) compatability with Mac OS Mountain Lion or Mavericks??

    Hi, I have Creative Suite 5.5 (5.1). I run on a mac pro OS 10.6.8 Snow leopard. I use Bridge & Photoshop the most. I can't & do not want to upgrade the adobe apps at this time. For various reasons it seems I should/ need to upgrade my OS. I could go

  • Edit changes not saved in CS5.5

    Several hours of edits were performed with frequent saves.  opened project next day and over 2 hour of edit changes were lost. Any one else run into this and is there a way to force the save?

  • Help me to display result

    this is my class that i want to get result from : class QuickSorter      long StartTime, EndTime,Compare=0, Move=0;      int[] array;      public QuickSorter(int[] unSorted)           array=unSorted; public void quickSort(int lowIndex, int highIndex)

  • IMac Core 2 Duo or Core i3?

    Looking to buy a used 27-inch iMac, 2009-2011 Unibody model primarily for Web & Email, i.e., not CPU intensive. Have two options at the same price point: one is a 3.06 GHz Core 2 Duo with 12 GB RAM, the other a 3.2 GHz Core i3 with 4 GB RAM. Is the C