6.11 JSP EXCEPTIONS

Exceptions in JSP can be handled by a special page. There is an object called Exception which is set by the container (only on the JSP Exception page). The JSP Exception page is marked by a directive as shown below.

<%@page isErrorPage=“true” %>

An example will make it clear. Consider a Form which accepts a PIN value as the password. The HTML is shown in Figure 6.6.

 

A sample index.jsp with exception through JSP

 

 

Fig. 6.6 A sample index.jsp with exception through JSP

 

Index.jsp captures the form data and hands it over to validateAndShow.jsp. The code shown in Figure 6.7 is written in a way to experiment with invalid data. In this case a non-numeric data on the PIN ...

Get Web Technology: Theory and Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.