• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Session Management - Servlets/JSP's

 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for suggestions on how to maintain a session. I do understand that once you create a session, it is maintained by the server and you don't have to do a thing. That is what people say. My issue here is this:

- After a 'successful' validation on login, the session is created in the LoginServlet by doing this (HttpSession session = request.getSession(); )
- After this I am transferred to the correct page. In that page I click a link that just goes to another JSP page without being mapped to a Servlet. When I go back to the original page, the session is forgotten.

Therefore, the session I created in the given Servlet is NOT maintained and is an issue for me.

Do I need to put some code in the JSP stating that there IS a session or...?

Any advice would be great. I will provide the code if necessary.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy McNally wrote:- After a 'successful' validation on login, the session is created in the LoginServlet by doing this (HttpSession session = request.getSession(); )

You do not know at this point whether the session is created or already existed. But you don't need to. As long as you get a session -- and there's no reason you shouldn't -- you could care less whether it's "new" or not.

- After this I am transferred to the correct page. In that page I click a link that just goes to another JSP page without being mapped to a Servlet.

Why? Bad practice.

When I go back to the original page, the session is forgotten.

What does "forgotten" mean? How are you ascertaining that it is "forgotten"?

Do I need to put some code in the JSP stating that there IS a session or...?

No.

I will provide the code if necessary.

First, describe what "forgotten" means. When code is necessary, please be sure it's an SSCCE.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You aren't making any other calls to session-related methods except getSession(), right?
 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is correct. I am not making any other session related calls other than getSession() in the initial Servlet to answer one of the questions you asked me.

Thank you for indicating to me, that even if I am going between JSP pages via a simple link it is a good idea to have it mapped to a Servlet Regardless. I at first didn't see that it was necessary but that may help in keeping a session going right?

FORGOTTEN: When I said this; it means that when I login successfully, I display the name of the user on the main page after log in also letting the user know what their registered email is which was retrieved from the database. This info comes from the Customer object I created originally IF login was valid.
--> When I click (ex: Contact Us JSP link) which isn't mapped to a servlet (just to clarify at this point) and then I click the link to go back to that main page that displays their Name and registered email, the area is blank and it is not displayed to user anymore.

Does this help clarify it a little more?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy McNally wrote:Thank you for indicating to me, that even if I am going between JSP pages via a simple link it is a good idea to have it mapped to a Servlet Regardless. I at first didn't see that it was necessary but that may help in keeping a session going right?

Unlikely related to the session issue; it's just bad practice not to go through a controller.

the area is blank and it is not displayed to user anymore.

So you're just relying on display for debugging? Any number of things can be going wrong. Time to add logging to the app to keep track of where and when either the scooped variable is no longer visible in the session, or the session id changes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!