Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

maintain session

  Asked By: Daryl    Date: Jul 25    Category: Java    Views: 672
  

I'm making a web site..I need to keep the session along pages
i.e when the user login he must be seen and known as long as he is in
my site

I use JSP and java beans..the problem is some pages keep the previous
session unless the user make "refresh"-"f5"
means that if 'x' login the page will say hi 'x', then when 'x' sign
out and 'y' login the page will still say hi 'x', which is wrong,
how can i solve this!!
and in other words is there some code to make automatic refresh!!

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Jana Franklin     Answered On: Jul 25

solve  that by make the logout page  send the user  to the home page for the site
and in the home page i use the invalidate function in jsp  code try this and let me know if there is some thing better please.

 
Answer #2    Answered By: Clay Cook     Answered On: Jul 25

It might be a client side caching thing, right? I remember there was a tag in the html header that used to adjust html caching policy. Try to set it to the most paranoid one and see how that works.

 
Answer #3    Answered By: Josephine Gomez     Answered On: Jul 25

try to invalidate the session  once the user  is attempts to log out; followed by removing any attribute of that session. utilize invalidate and removeAttribute of the session instance.

also you might want to consider a scope for the objects involved in the session or transactions. in that case when an old page  with old data has been visited (by pressing on back button), the content will not be shown as the session / objects instances have already been invalidated as part of logging out.

 
Answer #4    Answered By: Aadi Martin     Answered On: Jul 25

Do you invalidate the session  when x sign out ?

 
Answer #5    Answered By: Jawwad Akram     Answered On: Jul 25

This is strange! If you put some thing in the session  by using,
Session.setAttribute(“user_name”, “SampleUser”);

Then this session should be available and will always be accessible by session.getAttribute(“user_name”). So this will return SampleUser or null, if session expired. You can remove session attribute by session.removeAttribute(“user_name”).
So, all pages  should get same result when you call session.getAttribute(“user_name”), it does not depend on where you call this method.
Do you use back button?! I think you problem  may accrue in below sequence:
1) You login  to system by user  X
2) You click logout.
3) You click Browser Back button.
4) You see the cached page  which still says, hi ‘x’.
5) You press refresh and now the page actually requested from server.
Well, if this is the case you must handle it by writing a filter on your server and some javascript and meta data in your jsp  page.

 
Answer #6    Answered By: Shirley Allen     Answered On: Jul 25

I think It is the problem  of your login  system, you
should invalidate the session  on logout.

 
Answer #7    Answered By: Myrna Brown     Answered On: Jul 25

When you use javabean for your application you might set your scope into "application". If you store user  name in your javabean, this problem  might be happen.

 
Didn't find what you were looking for? Find more on maintain session Or get search suggestion and latest updates.




Tagged: