This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to take back the user to his personal page after a refresh

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After user logs in when he uses back browser button it takes him to the Login page. When he refreshes the page without entering any data the user is take back to his personal page. I am having problems in accomplishing this task. Give me some idea to solve this.

How to differentiate between the request coming via a refresh button and back browser button.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you record in the session some indicator of "where" the user "is" - that is, the identity of the page just presented, then you can check that in the next request and decide what to do with it.
Bill
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seriously I didn't understand what u said.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is one of many possible ways to do this.
Suppose that in the code that writes the "personal page" you do this:
session.setAttribute("where","personalpage" );

In your doGet or doPost, after getting the session:
String where = (String)session.getAttribute( "where" );

Now, if the request comes from the Login page, you can ignore the login form data and go straight to the personal page presentation.

Bill
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a well-designed login jsp page with all the cache controlling mechanics enabled for the page(to reflect the state of the model). Once when the user enters loginName/Password control transfers to controller servlet. I had used a sendRedirect to tranfer the user to his personal page after setting the username in session attribute.

Now user is in his personal page. Without logging out when the user clicks Browser Back Button, a get request is made for the Login.jsp page. Since cache controlling is enabled both the userName/Password textboxes are empty. Here when the user clicks the refresh/reload button he should be taken back to his personal page since he hasn't logged out of his session.

It is here I am getting the problem.

Is there a way to find the difference between the request made by a Browser Back Button and Refresh/Reload button.

I had set a session attribute in personal page, evaluate that session attribute in login.jsp page and send him back to his personal page. This is fine when the user uses refresh/reload button. But the same logic happens even when the user clicks his Browser Back Button. Since both makes a get request.

How to solve this issue.
[ November 17, 2005: Message edited by: Vishnu Prakash ]
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read William Brogden's comment your answer is there.

Whether you do back or refresh, the browser generates only requests (get or post in this case) to the server. There is no way to distinguish between the request generated from a back button, refresh or submit. If you have an indication of where user is or status of user (logged in or logged out) in session, this is easy to do. Did you try what William told?

Since you mentioned that you are doing get it is not the double click problem described here http://theserverside.com/articles/article.tss?l=RedirectAfterPost

Could it be your browser caching the logging page?
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whether you do back or refresh, the browser generates only requests (get or post in this case) to the server. There is no way to distinguish between the request generated from a back button, refresh or submit.


Thanks for the information.


If you have an indication of where user is or status of user (logged in or logged out) in session, this is easy to do.


In my case user is logged in.

I had set the userName as session attribute in personal page, evaluated that session attribute in login.jsp page and if the user is still in the session transfer him to his personal page. This is fine when the user uses refresh/reload button. But the same logic executes even when the user clicks his Browser Back Button. Since both makes a get request.

LoginPage.jsp

<%
String userName = (String) session.getAttribute("username");
if(userName!= null) {
System.out.println("In Session user: " + str);
response.sendRedirect("/PostRedirectGet/PersonalPage.jsp");
%>

Note: Try this

Log in to your Yahoo account. You will be taken to your personal page. Now just click the Browser Back Button. You will be taken back to your log in page. (You are still a logged-in user which means user is in session). Now click the refresh/reload button. You will be taken back to your pesonal page without requiring to type in your username/password.

I like to do the same thing in my application.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone care to answer this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic