aspose file tools*
The moose likes JSP and the fly likes Force execution of JSP code when pressing back button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Force execution of JSP code when pressing back button" Watch "Force execution of JSP code when pressing back button" New topic
Author

Force execution of JSP code when pressing back button

Sam Seaver
Greenhorn

Joined: Nov 10, 2003
Posts: 4
Dear all:
I have this JSP code that creates a new random ID everytime I run it:
StringBuffer s=new StringBuffer();
for(int i=0;i<10; i++){
int nextChar=(int)(Math.random()*62);
if(nextChar<10) //0-9
s.append(nextChar);
else if (nextChar<36) //a-z
s.append((char)(nextChar-10+'a'));
else
s.append((char)(nextChar-36+'A'));
}
jID = s.toString();
my problem is that when I press the back button, this code does NOT re-execute, thus the ID remains the same, and it shouldn't. I've messed around with the session, but my problem with them is that I use applets in the web application and it's basically just easier to generate a new ID every time.
Can someone help me here?
Thanks
S
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

When the back button is pressed the browser generally will not go back to the server and re-run the page.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
hmm, from another thread this code has appeared:
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
try that in the html and see if it works to stop the browser caching and so having to request the page again.
is your problem for development purposes or do you need to do it for real viewers too? coz if its just for dev go into ur browser prefs and turn off caching altogether


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Sam Seaver
Greenhorn

Joined: Nov 10, 2003
Posts: 4
OK, I tried the Expires = -1, but that didnt work.
So I understand now, the back is only for the last html, regardless of sessions and jsp settings etc. right?
so my latest idea is to have a count in javascript, assuming that the browser runs the javascript everytime it loads the html. So the javascript will keep a count of every time it goes back to this particular page, and disable the page if the count is the second time.
is this possible?
Sam
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

is this possible?

Not really. Where would you store the count? In the page? That gets reloaded every time, so there's no place to accumulate a count.
What are you really trying to achieve? Depending on the back button in a web application will lead you to nothing but frustration.
bear
Sam Seaver
Greenhorn

Joined: Nov 10, 2003
Posts: 4
My problem is that Im trying to stop a user from reloading a web-page with the same ID...by simply trying to change the ID every time the page is reloaded...
should I write the ID in javascript?
Sam
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Are trying to solve the age-old problem of detecting when a page is being re-submitted as a result of Back? and therefore trying to re-do an operation like a database insert, delete or update? What is the purpose of your 'id'?
bear
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
i don't know much about javascript but javascript can access cookies can't it? and if so then presuming cookies are on then yes you should be able to detect via javascript. of course javascript itself may be turned off in the browser.
you may simply want to use ip tracking to stop a user resubmitting a form many times quickly or whatever your trying to do
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Force execution of JSP code when pressing back button