• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seriously I didn't understand what u said.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone care to answer this
reply
    Bookmark Topic Watch Topic
  • New Topic