0

我有一个用于向数据库插入一些值的 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);
    } 
}
4

1 回答 1

1

添加

response.sendRedirect("confirmpage.jsp");

并制作一个确认页面以重定向到。这是绝对必要的。你不应该在没有重定向到另一个页面的情况下进行数据库更新/插入。

为确保您的确认页面准确无误,您可以在会话中存储需要在其上显示的任何信息,然后从那里读取。

于 2013-10-09T19:00:12.863 回答