Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with session tracking

 
Maria Peter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me I am lost
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think we all are.
from what you have said I have no idea what you are doing or why you are doing it.
 
Maria Peter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys I was using response.sendRedirect
Thank you so much for your help
Maria
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic