wood burning stoves 2.0*
The moose likes JSP and the fly likes Problem with session tracking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with session tracking" Watch "Problem with session tracking" New topic
Author

Problem with session tracking

Maria Peter
Greenhorn

Joined: Oct 27, 2003
Posts: 29
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

Thanks in advance
Maria Peter
Greenhorn

Joined: Oct 27, 2003
Posts: 29
please help me I am lost
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
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.
Maria Peter
Greenhorn

Joined: Oct 27, 2003
Posts: 29
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
Sona Bhavani
Greenhorn

Joined: Nov 12, 2003
Posts: 6
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

The session object is lost if a new request is created.

Actually the session should stay around across requests. That is its entire purpose.
bear
[ November 19, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

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.
Maria Peter
Greenhorn

Joined: Oct 27, 2003
Posts: 29
Thank you guys I was using response.sendRedirect
Thank you so much for your help
Maria
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61426
    
  67

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
Sona Bhavani
Greenhorn

Joined: Nov 12, 2003
Posts: 6
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.
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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

hth
MB


Malhar Barai
SOA & Java Book
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with session tracking