java - New Session is created with each servlet request from JSPs? -
i have legacy java 1.6 running localhost tomcat 7 application using jsp pages, frameset frames, javascript, no framework struts. pass object display in page servlet using request or session , works fine.
however, made changes , can't retrieve same object session or request. had been working fine previously, i'm not sure broken, can't send string value jsp's servlet.
i created new stripped down jsp , can't either using request or session. same thing when push code our tomcat 6 web server. using debugger, see objects populated in session, lost later when new session created each time in using simple code sessionid:
system.out.println("the session id is: " + session.getid()); the session id is: eb431c19b41957b2bb2efc3dbaf32241
the session id is: c9cbd30e84d5c93df6114c1412ae5523 see in firebug under header, response headers:
set-cookie jsessionid=c9cbd30e84d5c93df6114c1412ae5523; path=/name omitted here/; httponly,
so know cookies set. removed jquery , i"m stripping down jsp code as possible, doesn't seem issue.
i'm using: httpsession session = request.getsession(true); using false didn't matter.
session.setattribute("objnamelist", objnamelist); the context.xml has cookies set true , use response.sendredirect, if error thrown in: response.sendredirect("error.jsp"); there no place in code session invalidate either.
all i'm doing jsp sending form using like:
document.formname.submit(); works fine. using code try , set simple string in session doesn't work either:
session.setattribute("somevalue","somevalue"); gives me null in servlet here:
string val = (string) session.getattribute("somevalue"); any ideas causing this?
resultion:
it turned out issue url, typo actually, balusc mentioned, path session cookies didn't match between jsp , servlet.
doublecheck if request url servlet matches session cookie domain , path. if doesn't match, browser won't send session cookie along request , server think there's no means of established session , therefore create new one.
you can check cookies in http traffic monitor of browser's web developer toolset (press f12 in chrome/firefox23+/ie9+ , open "network" tab). when new session starts, server must have returned response set-cookie header therein cookie value , path (and implicitly domain). when browser sends subsequent request on same domain , path, must have passed cookie via cookie request header.
Comments
Post a Comment