• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simplest way to prevent resubmitting the same page?

 
archana vishwanath
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem::
User again and again refreshing the web page,and data again and again
getting inserted into the database.
Though there are millions of ways to prevent this.I always wish for the simplest trick to do this.Can anyone tell me that?

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say using sessions would stop it
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first time the JSP is sent add a hidden field to the form. When that field is set refrain from doing the database action when the form is submitted again.
 
archana vishwanath
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jerone could you please ellaborate it a little more clear?
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you can do is set a session variable after insterting to db
session.setAttribute("checkpoint","true");
and before inserting check like this
if(session.getAttribute("checkpoint2")=="true")
{
//give the message to the user already inserted
}
else
{
//do the insert
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!