GeeCON Prague 2014*
The moose likes Servlets and the fly likes how to deal with page refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "how to deal with page refresh" Watch "how to deal with page refresh" New topic
Author

how to deal with page refresh

Blood Bigsoon
Greenhorn

Joined: Jun 03, 2001
Posts: 13
help me!
I had wrote a jsp to update my database .but each time the user refresh the jsp page,the update would invoke one time.how to prevent it?
HASIKA NANAYAKKARA
Greenhorn

Joined: Jun 03, 2001
Posts: 6
I GUESS THAT U UPDATE THE DATABASE ON A CLICK EVENT OF A SUBMIT BUTTON;ASSUME THE CAPTION OF THE BUTTON IS "UPDATE" AND THE BUTTON NAME "btnUPDATE".TRY THE FOLLOWING METHOD.IT COULD WORK
<%
String BUTTON=request.getParameter("btnUPDATE");
if(BUTTON==null)BUTTON="NULL" ;
if (BUTTON.equals("UPDATE")){
://WRITE THE REQUIRED DATABASE UPDATE CODE HERE
://WITHIN THE IF CONDITION
}
%>
Blood Bigsoon
Greenhorn

Joined: Jun 03, 2001
Posts: 13
but if the user refresh the page ,then the update sql will execute again,i had found a way:
<% response.setHeader("Expires", "-1"); %>
is it right?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"bigsoon",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
GeeCON Prague 2014
 
subject: how to deal with page refresh