Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Force execution of JSP code when pressing back button

 
Sam Seaver
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the back button is pressed the browser generally will not go back to the server and re-run the page.
bear
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sam Seaver
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic