响应.jsp中的sendRedirect错误



我是一个Java新手/业余程序员,我正在编写一些代码来帮助我添加记录,搜索和更新我广泛的电影收藏数据库。我已经编写了使用jsp添加和搜索记录的代码,它工作得很好。但是,我遇到了代码更新记录的问题。我在JSP中得到以下错误,它似乎引用了我使用的response.sendRedirect()方法:


org.apache.jasper。JasperException:处理过程中出现异常JSP page/updateRecord.jsp第63行

63: response.sendRedirect("updaterecordsuccess.html");


问题是,我在另一个JSP中使用了基本相同的代码,除了sql更新字符串之外,它工作得很好。给出错误的JSP页面的完整代码如下所示。response.sendRedirect方法位于代码的最后一行。我想我什么都检查过了,但还是没有弄明白。

 <%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*"    import="java.text.ParseException" import="java.text.SimpleDateFormat" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
  Connection conn = null;
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  conn = DriverManager.getConnection("jdbc:mysql://localhost/VideoDB?  user=user&password=password");
  PreparedStatement psUpdateRecord=null;
  String sqlUpdateRecord=null;

  String title=request.getParameter("title");
  String sDateVwd=request.getParameter("sDateVwd");
  int rating=Integer.parseInt(request.getParameter("rating"));
  String comments=request.getParameter("comments");
  try {
        java.util.Date utilDateVwd = new SimpleDateFormat("dd MMM   yyyy").parse(sDateVwd);
        java.sql.Date sqlDateVwd = new java.sql.Date(utilDateVwd.getTime());
    try {
     sqlUpdateRecord="UPDATE vidtb SET date_vwd = ?, rating = ?, comments = ? WHERE  title = ?";
     psUpdateRecord=conn.prepareStatement(sqlUpdateRecord);
     psUpdateRecord.setDate(1,sqlDateVwd);
     psUpdateRecord.setInt(2,rating);
     psUpdateRecord.setString(3,comments);
     psUpdateRecord.setString(4,title);       
     psUpdateRecord.executeUpdate();
      } finally {
    }
  } 
  catch (ParseException e) {
    e.printStackTrace();
  }
  catch(Exception e)
  {
      response.sendRedirect("rateRecord.jsp");//// On error it will send back to   rateRecord.jsp page
  }
    try{
      if(psUpdateRecord!=null)
      {
       psUpdateRecord.close();
      }
      if(conn!=null)
      {
       conn.close();
      }
    }
    catch(Exception e)
    {
      e.printStackTrace(); 
    }
response.sendRedirect("updaterecordsuccess.html");
%>

我错了!我在家里的另一台电脑上随意工作,决定尝试对数据库中的记录进行更新,并且成功了。我猜是我另一台电脑上的浏览器缓存了不好的结果。所以代码都没问题。谢谢你的建议。

最新更新