Results 1 to 4 of 4

Thread: Handle exceptions from jsp page

  1. #1
    Join Date
    Jan 2009
    Posts
    65

    Handle exceptions from jsp page

    Hi, can anyone provide me the details of handling exceptions with the help of jsp? I know how to handle exceptions in c++, but beginner in jsp and want to handle one exception. Please help me as soon as possible.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Handle exceptions from jsp page

    Hi, I am also beginner in Jsp and not have much knowledge. But know basics of exception handling in jsp page. Ehen any runtime exception occur that can be handled easily with the help of jsp applications as they are stored one at a time in the implicit object named exception. You can use the exception object in an error page where you display the name of exception and its stack trace class and the message which you want to display if the exception occurs. A JSP page specifies the error page with the page directive and errorPage attribute. If an unhandled exception occurs, then regardless of the execution of that code further the code directly moved to the error page.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Handle exceptions from jsp page

    Hi, if you want to learn exception handling in jsp, just try the following code one by one and learn.

    save it as first.html

    Code:
    <html>
    <head>
    </head>
    <body>
    <form action="FormHandler.jsp" method="post">
    	Enter your age ( in years ) : 
    	<input type="text" name="Age" /> 
    	<input type="submit" value="Submit" />
    </form>
    </body>
    </html>
    Save this as firstHandler.jsp

    Code:
    <%@ page errorPage="ExceptionHandler.jsp" %>
    <html>
    <head>
    </head>
    <body>
    <%
    	int age;
    	age = Integer.parseInt(request.getParameter("Age"));
    %>
    <p>You are of age : <%= age %> years.</p>
    <p><a href="Form.html">Back</a>.</p>
    </body>
    </html>
    If exception occur while storing your age or something the error page is displayed with the help of following:

    Save it as ExceptionHandler.jsp

    Code:
    <%@ page isErrorPage="true" import="java.io.*" %>
    <html>
    <head>
    <title>Exceptional Even Occurred!</title>
    </head>
    <body>
    <%= exception.toString() %><br>
    </font>
    <%
    out.println("<!--");
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    exception.printStackTrace(pw);
    out.print(sw);
    sw.close();
    pw.close();
    out.println("-->");
    %>
    </body>
    </html>

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Handle exceptions from jsp page

    Hi, to handle exceptions from jsp page JSP page specifies the error page with the page directive and errorPage attribute. If an unhandled exception occurs the error page is immediately executed. Look at the following code example of jsp page errpage.jsp to be the error page:

    Code:
    < @ page errorPage errpage.jsp >
    <
    if (request.getParameter( param ).equals( value )) 
    {
    ........
    }
    if ( value .equals(request.getParameter( param ))) 
    {
    ........
    }
    >
    The error page indicates that it is an error page with the page directive and isErrorPage attribute. Below is an example of an error page that prints the name of the exception which is unhandled:

    Code:
    < @ page isErrorPage true >
    An unexcepted error occurred. The name of the exception is:< exception >

Similar Threads

  1. Resource Exceptions
    By shoppingboy in forum Windows Software
    Replies: 2
    Last Post: 05-03-2010, 08:40 PM
  2. Exceptions of PHP in set_exception_handler?
    By - Empty Shell - in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 02:12 AM
  3. What are Exceptions in PHP 5?
    By DANIEL 602 in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 01:35 AM
  4. What is Log .NET Exceptions
    By Agneya in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 01:34 AM
  5. PHP Error exceptions
    By nehal_serpa in forum Software Development
    Replies: 3
    Last Post: 01-05-2009, 06:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,637,527.11401 seconds with 16 queries