2013-10-09 67 views
0

我有一個jsp頁面用於向數據庫中插入一些值。當刷新頁面時,將重複值插入到數據庫表中。如何防止這種情況發生?如何防止在刷新Jsp頁面時將值插入數據庫?

try { 
    //here all values are retrieve using request.getParameters 
    if(sage!=null) { age=Integer.parseInt(sage); } 
    if(contact!=null) { phone=Long.parseLong(contact); } 
    db.connect(); 
    int res=0; 
    String sql="insert into phr_login(name,address,age,phone,email,username,password,salt,category)values('"‌​+name+"','"+address+"',"+age+","+phone+",'"+emailId+"','"+userId+"','"+epassword+‌​"','"+salt+"','"+category+"')"; 
    if(name!=""&&userId!=""&&password!=""&&emailId!="") { 
     res=db.updateSQL(sql); 
    } 
} 
+0

通過存儲事實,你已經在該頁面相關的會話中插入了該呼叫的內容? – fvu

+0

你能提供一些代碼嗎? –

+0

如何防止這種情況? – sufala

回答

1

添加

response.sendRedirect("confirmpage.jsp"); 

並進行確認頁面重定向到。這是絕對必要的。之後不應該進行數據庫更新/插入而不重定向到其他頁面。

爲了確保您的確認頁是準確的,您可以存儲任何需要在會話中顯示的信息,然後從中讀取。

相關問題