This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I just put my session tracking code in header.jsp file and i use <%@ include file="/jsp/header.jsp" %>
First I login through login.jsp -> it takes me to TestServlet, I retrive some data from the database and dispaly it back in test.jsp Update button in test.jsp screen takes me back to TestServlet and from the TestServlet it forwards(Request Dispatcher) request to update.jsp test.jsp -> TestServlet -> test.jsp -> TestServlet -> update.jsp -> TestServlet ->test.jsp session is available till update.jsp after that i get null for the seeion value I am using SessionCalss sess = (SessionClass) session.getAttribute ("INFO"); and i also tried to use hidden field for session in jsp and retrive the value in servlet using rea.getParameter but the result is same I am not able to understand why i am able to get the session after update.jsp? Am I doing any thing wrong? Is there any better way to achieve the same
i think we all are. from what you have said I have no idea what you are doing or why you are doing it.
Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Joined: Oct 27, 2003
Let me make my long story short. Once the user is logged in I get the valid session, and for the third request I am loosing the session. I get seesion object as null. Please let me know is there any way I can avoid this Thanks in advance Maria
hi, check out your flow.The session object is lost if a new request is created.So check out in your program flow you are you forwarding the request or redirecting it.I was facing a similar problem.I was using response.sendRedirect and later i learnt that if i need to maintain the session i have to use jsp forward.Based onthat i am suggesting you.i am not very sure about this. Sona.
The most likely cause of losing a session is losing the cookie that the container sets in order to maintain the session across requests. As your first debugging step, please make sure that your browser is set up to accept cookies. Since HTTP is a stateless protocol, the session is the means by which state can be maintained across multiple HTTP requests. The session is stored on the server and each request "hooks up" to the session via a "session key" stored in a cookie created by the container. Whether you use a redirect or a forward is immaterial. As long as the cookie is valid (and the session has not timed out), your session should be available to all requests being made from your web app. bear P.S. In the absence of cookies, sessions can be maintained using a technique known as "URL rewriting" which essentially tacks the session key onto the request as a parameter.
Joined: Oct 27, 2003
Thank you guys I was using response.sendRedirect Thank you so much for your help Maria
Maria, please read my response. It's ok to use response.sendRedirect. If you are losing the session across a redirect, something else is wrong and you may have more problems in other places in your application that may need to rely upon session data. bear
Joined: Nov 12, 2003
But how do we know whether the client who uses the application has cookies enabled in his browser?so what approach should we follow to maintain the session? Thanks and Regards. Sona.
Originally posted by Sona Bhavani: But how do we know whether the client who uses the application has cookies enabled in his browser?so what approach should we follow to maintain the session? Thanks and Regards. Sona.
If cookies are disabled, the container switches to URL rewriting, that is the session id is passed through the URL. But if you are using response.sendRedirect then to be able to do URL rewriting, all the statements with response.sendRedirect should have