• Post Reply Bookmark Topic Watch Topic
  • New Topic

go back history

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was putting this code in my jsp page if error occured
<a href="javascript:history.go(-1)">Click here to go back</a>
Now beside forward back, i want to do something in my java code and then forward back, how i can "memorize" the previous page?
Can any one of the HttpServletRequest method help me? getRequestedSessionId() or getRequestURI() ?
Thanks!
 
Chris Smith
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "do something in your Java code"? You can call Java code directly from the JSP code itself, through a scriptlet, bean, or custom action. That avoids the whole problem.
If you want to remember the previous page, though, it's trivial to store it in the session object at the beginning of each request using HttpServletRequest.getRequestURI(). You can then offer a link to that URI.
Chris
 
Felix Kan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you choose to use javascript:history.go(-1) there is nothing you can do. the whole process is 100% client-side and involves no extra http connection back to your server. Simply put, that javascript intructs your browser to step back, grabs the copy from browser's cache, and display. Some browsers are "smart" enough to remember what you've entered in the previous page, but it's not consistent.
Avoid using javascript if you want to guarantee this "memorizing" feature, as suggested by Chris.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!