This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

redirecting a logged in user to the previous page  RSS feed

 
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: 22374
42
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: 66143
141
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!