示例:
<%!
String getFormattedDate() {
...
throw new IllegalArgumentException(...); // 错误
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello, JSP!</title>
</head>
<body>
<i>Today is <%= getFormattedDate() %></i>
</body>
</html>
注意: 这样的 JSP 页面会编译,因为 servlet 容器将所有 JSP 代码包装在 try {} catch() {} 块中,但它们在服务器上部署时会产生运行时异常。