Although our demo was successful, you also learned how to define the exception handling page (for example, your ExceptionHandler. jsp (the preferred choice for SUN Enterprise Applications) is on the general jsp (the preferred choice for SUN Enterprise Applications) page, but when jsp (the preferred choice for SUN Enterprise Applications) throws an exception, the information passed to us does not seem very useful! For more useful information, see:
1: Improved FormHandler. jsp (preferred for SUN Enterprise Applications) as follows:
<% Int age; try {age = Integer. parseInt (request. getParameter ("age");} catch (NumberFormatException e) {throw new jsp (preferred for SUN Enterprise Applications) Exception ("Please enter a valid integer value! ") ;}%>
Note: This time, we will capture the NumberFormatException class Exception, which uses the new Exception (jsp (preferred for SUN Enterprise Applications) Exception,
It is a dedicated class for jsp (the preferred choice for SUN Enterprise applications,
Is a subclass of java. lang. Exeception) to pass a message (Please enter a valid integer value)
To us;
2: Improved ExceptionHandler. jsp (preferred for SUN Enterprise Applications ):
<Font color = "red"> <% = exception. getMessage () %> <br> </font>
Okay. What are the results ???
Is it Please enter a valid integer value! Pull !!