Sun Java Solaris Communities My SDN Account
 
Tutorials & Code Camps

jGuru: Help: Exception Handling in JSP

 


[Exercise | API Docs | Short Course| Exercises]

Help is available for each task.

Task 1

Design a JSP page called errhandler.jsp that can process a POST operation.

For convenience, the HTML form can be developed as part of the JSP page itself. Note that the form's ACTION clause must point to the JSP page itself. Also, make sure that the form contains an input element like a radio button.

Task 2

Indicate an error page, errorpage.jsp, using the page directive for the JSP page.

Uncaught runtime exceptions are automatically forwarded to an error page, if specified, by the JSP engine. The location of the error page can be specified using the errorPage attribute of the page tag.

Task 3

Process the posted form elements. Throw an exception if the value posted for the input element is not equal to an expected value, else print an acknowledgement back to the user.

The form elements can be obtained using the request.getParameter() method. You can echo a message to the browser using response.println(). You can throw a generic exception using new Exception("some message").

Task 4

Develop an error page, errorpage.jsp, which can access the runtime exception.

A JSP error page is developed by setting the isErrorPage attribute of the page tag to true. The runtime exception can be accessed by means of the JSP implicit variable exception.

Task 5

Deploy the JSP files for the example within Tomcat.

Assuming you have installed Tomcat in say, \jakarta-tomcat, copy the two JSP files to \jakarta-tomcat\examples\jsp\jdc\errHandling\

Task 6

Run the error handling example.

From your browser, access the URL http://localhost:8080/examples/jsp/jdc/errHandling/errhandler.jsp

Copyright 1996-2000 jGuru.com. All Rights Reserved.

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.