I thought that at first too Guru, I had to go remind myself... looking at the javadoc for request.getSession(boolean)...
"Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session." That "OR, IF" clause is whats important.. it should only create a new session if none already exists. So, calling getSession(true) is going to return to you a session either way, whether it's a pre-existing one or a new one. I do however agree that calling getSession(true) in this case does not seem appropriate... Angelina, I would call it with false and check for null, as Guru says. It probably won't solve the problem, but it will tell you a little bit more, namely whether the session really exists or not in a more explicit manner. -- Frank W. Zammetti Founder and Chief Software Architect Omnytex Technologies http://www.omnytex.com On Mon, June 27, 2005 12:23 pm, Raghupathy,Gurumoorthy said: > Well the issue is > > request.getSession(true) > > Try something like > > MyObject myObj = new MyObject(); > myObj.setAbc("Abc"); > myObj,setDef("Def"); > HttpSession session = request.getSession(false); > > If ( session == null ) { > session = request.getSession(true); > } > > session.setAttribute(MySessionName, myObj); > > > > > HttpSession session = request.getSession(false); > > If ( session != null ) { > MyObject myObj = > (MyObject)request.getSession(true).getAttribute(MySessionName); > } > > > Because HttpSession session = request.getSession(true); will always create > a > new session > > Regards > Guru > -----Original Message----- > From: angelina zh [mailto:[EMAIL PROTECTED] > Sent: 27 June 2005 17:18 > To: Tomcat Users List > Subject: Re: http session lost between struts action > > > David, > > Thanks a lot for your help. > > My browser accepts cookies. Actually I inspected the cookies as well as > the > session object when I was debugging. The cookies is a valid array with > valid > sessionId inside and the method isRequestedSessionIdFromCookie() returns > true as long as the http session object is valid. But when the session got > lost, the cookies became to null and the method > isRequestedSessionIdFromCookie() returns false. > > The links are the paths defined in the struct-config.xml file. The > jsessionid is still valid when the session get lost. > > Here is how the code looks like in the LogInAction: > MyObject myObj = new MyObject(); > myObj.setAbc("Abc"); > myObj,setDef("Def"); > HttpSession session = request.getSession(true); > session.setAttribute(MySessionName, myObj); > > Here is how the code looks like in the following actions: > MyObject myObj = > (MyObject)request.getSession(true).getAttribute(MySessionName); > > I have a FrontController servlet class to hand request and response. When > a > link on the welcome page got clicked, I noticed that in the > FrontController > servlet class, the session in the request became to null via eclipse's > debugging tool. (Before this point, the session is all valid.) Then in the > following action class, a new standard session got created. So my personal > session information totally lost. > > Anything else I shall try? > > Thanks so much! > > Angelina > > David Smith <[EMAIL PROTECTED]> wrote: > Check these: > > 1. Your browser is accepting cookies > 2. Your links are being generated by taglibs that insure the jsessionid > is attached if needed. I say if needed because if tomcat is getting a > valid session cookie from your browser, the jsessionid won't be added to > the link. > > They don't both have to be done, but chances of eliminating errors are > best if they are. Beyond that, I would have to suspect the way you are > trying to access the session attributes either in setting them or in > retrieving them. Could you post code snippets that show how you are > setting and retrieving attributes? > > --David > > > > > --------------------------------- > Yahoo! Sports > Rekindle the Rivalries. Sign up for Fantasy Football > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]