JSP exception processing (2)

xiaoxiao2021-03-06  102

Although our demonstration is very successful, and makes you understand how to define the exception handle page (such as: Your ExceptionHandler.jsp) in a normal JSP page, but when the JSP throws exceptions, the information passed to us is not very Useful! To get more useful information, please see: 1: Improve formhandler.jsp as follows:

<%

Int agec;

Try {

Age = Integer.Parseint (Request.GetParameter ("age");

} catch (NUMBERFORMATEXCEPTION E) {

Throw new JSPEXCEPTION ("Please enter a valid integer value!");

}

%> Note: This time we will capture the Numberformatexception class exception, which uses new exceptions (JSPEXCEPTION, which is a JSP-specific class, is a subclass of java.lang.exeception) Pass a message (please enter a valid integer value) we;

2: Improve the ExceptionHandler.jsp as follows: That is changed to

<% = exception.getMessage ()%>

Ok, try again: What results ??? Is the please entry a valid integer value! pull!!

转载请注明原文地址:https://www.9cbs.com/read-97195.html

New Post(0)