Tomcat5.5.9处理页面错误的问题

cbcbbcbc 2005-07-25 09:54:59
我在一个文件NewBookHandler.jsp中设置errorPage为ExceptionHandler.jsp,然后将ExceptionHandler.jsp的isErrorPage设置为true。按道理NewBookHandler.jsp出错时将导向ExceptionHandler.jsp,但是,我发现只要ExceptionHandler.jsp中存在<% page isErrorPage="true" %>,则必定会出现HTTP 500内部服务器错误。调试跟踪了一下,发现ExceptionHandler得代码正常执行完了,中间没有出现异常。请问是否是tomcat本身的BUG啊?

================================ NewBookHandler.jsp ==============================
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page errorPage="ExceptionHandler.jsp" %>
<%@ page import="java.sql.*" %>

<html>
<head>
<title>提示</title>
</head>
<body>
<%
String id = request.getParameter("id");
String name = request.getParameter("name");
String sPrice = request.getParameter("price");
String desc = request.getParameter("desc");

if(id == null || id.trim().length() == 0) {
throw new Exception("请输入编号!");
}
if(name == null || name.trim().length() == 0) {
throw new Exception("请输入书名!");
}
if(sPrice == null || sPrice.trim().length() == 0) {
throw new Exception("请输入价格!");
}
int price = 0;
try {
price = Integer.parseInt(sPrice);
} catch(NumberFormatException e) {
throw new Exception("价格应该为数字!");
}
if(price <=0) {
throw new Exception("价格应该大于0!");
}

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = null;
PreparedStatement ps = null;
try {
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB"
, "sa"
, null);
// 重要: 尽量用参数化的SQL
String sql = "INSERT INTO T_Book(FID, FName, FPrice, FDesc) VALUES(?, ?, ?, ?)";
ps = conn.prepareStatement(sql);
ps.setString(1, id);
ps.setString(2, name);
ps.setInt(3, price);
ps.setString(4, desc);
System.out.println(ps.executeUpdate() + " records inserted");
} catch(Exception e) {
throw new Exception("插入失败" );
} finally {// 非常重要:无论成功失败都必须释放语句
if(ps != null) {
ps.close();
}
if(conn != null) {
conn.close();
}
}
%>
添加成功!
</body>
</html>

============================= ExceptionHandler.jsp ===============================
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page isErrorPage="true" %>

<html>
<head>
<title>错误</title>
</head>
<body>
<%= exception.getMessage() %>
<p><input type="button" value="返回修改" onclick="history.back()"></p>
</body>
</html>
...全文
34 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧