[英]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.