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.
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.
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.
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
Save this as firstHandler.jspCode:<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>
If exception occur while storing your age or something the error page is displayed with the help of following: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>
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>
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:
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 errorPage errpage.jsp > < if (request.getParameter( param ).equals( value )) { ........ } if ( value .equals(request.getParameter( param ))) { ........ } >
Code:< @ page isErrorPage true > An unexcepted error occurred. The name of the exception is:< exception >
Bookmarks