File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to take back the user to his personal page after a refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to take back the user to his personal page after a refresh" Watch "How to take back the user to his personal page after a refresh" New topic
Author

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

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: Nov 15, 2004
Posts: 1026
Seriously I didn't understand what u said.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: Nov 15, 2004
Posts: 1026
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

Joined: Oct 12, 2004
Posts: 306
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

Joined: Nov 15, 2004
Posts: 1026

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

Joined: Nov 15, 2004
Posts: 1026
Anyone care to answer this
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to take back the user to his personal page after a refresh