繁体   English   中英

jsp中的response.sendRedirect错误

[英]response.sendRedirect Error in jsp

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


org.apache.jasper.JasperException:在第63行处理JSP页面/updateRecord.jsp时发生异常

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");

%>

我的错! 我在家里随便用另一台计算机工作时,决定尝试对数据库中的记录进行更新,然后它起作用了。 我猜我另一台计算机上的浏览器正在缓存不良结果。 因此,对代码来说一切都很好。 无论如何,谢谢您的建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM