• Post Reply Bookmark Topic Watch Topic
  • New Topic

redirecting a logged in user to the previous page

 
Bala Krishna
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that if I try to respond to a post without logging in, Javaranch redirects me to the login page, and once I login, takes me back to the original page I was on, before logging in.
One approach I can think of to do this, is to examine the session for the user's credentials, and if the user has not logged in, redirect him/her to the login page, with a query string that gives the value of the page the user should be sent to, once he/she logs in. But, there has to be a better way of doing this. How does Javaranch do this?
 
Bala Krishna
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Responses! . I was curious about how Javaranch handles this and hoped that the moderators would know the answer to my question and respond.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how JavaRanch does it. But if I wanted to do that, here's how I would do it:

1. Store the URL of the requested page somewhere. E.g. in a session variable or as a parameter of the URL being redirected to.

2. Have the login page retrieve that URL and redirect to it after successful login.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've used hidden elments quite successfully for this purpose.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!