0

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

%>
4

1 に答える 1

0

悪い!私は何気なく自宅の別のコンピューターで作業していたので、データベース内のレコードを更新しようとしましたが、うまくいきました。他のコンピューターのブラウザーが悪い結果をキャッシュしていたと思います。それで、コードはすべて問題ありません。とにかく提案をありがとう。

于 2012-12-30T18:49:18.560 に答える