getMessage()
返回值:異常物件的訊息字串。<%@page language = "java" pageEncoding="GBK" errorPage="error.jsp"%> <% Integer.parseInt("測試"); %>在 error.jsp 頁面輸出異常訊息,關鍵程式碼如下:
<%@page language="java" pageEncoding="GBK" isErrorPage="true"%> <% out.print(exception.getMessage()); %>
<%@page language="java" import="java.util.*" pageEncoding="gbk" errorPage="error.jsp"%> <body> <% int apple = Integer.parseInt("ad");//將字母轉換為int型別 out.println("蘋果每斤"+apple+"元"); %> </body>編寫 error.jsp 頁面,用於接收傳遞的異常資訊,關鍵程式碼如下:
<%@page language="java" import="java.util.*" pageEncoding="gbk"isErrorPage="true"%> <body> 錯誤提示<%=exception.getMessage()%> </body>