RE: http session lost between struts action

2005-06-27 Thread angelina zh
Frank,  Guru
 
Thank you guys so much for the comments. But I forget to mention that the code 
was originally coded to request.getSession(false). Since it did not work for 
me, I changed to request.getSession(true).
 
So neither was working for me.
 
Angelina

"Frank W. Zammetti" <[EMAIL PROTECTED]> wrote:
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 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]


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: http session lost between struts action

2005-06-27 Thread angelina zh
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

Re: http session lost between struts action

2005-06-27 Thread angelina zh
Jack,
 
I dont understand why you keep saying there is nothing worng. The session got 
established at the log in page and kept valid in the security re-diredct pages 
till the welcome page. Then session got lost. Why there is nothing wrong with 
it?
 
The session id did not get lost, just the http session lost.
 
Regards,
 
Angelina

Dakota Jack <[EMAIL PROTECTED]> wrote:
There is nothing wrong. You don't have a new session in your browser.

On 6/23/05, angelina zh wrote:
> Hi,
> 
> Can anyone please help me on this session lost issue?
> 
> Here is the problem I am getting:
> 
> -- If I open a IE 6.0 browser and log into the web site we are developing, I 
> get into a welcome page with a few of link options. In the login action 
> class, we set some attributes into the session. If I click on any of the 
> links, I got null pointer exception in next action class when we try to get 
> attributes from the session. I tried to use Eclipse to debug, noticed that 
> the session of the request after the welcome page became to null.
> 
> --If I keep that browser open and go to the log in page again. After I log 
> in, I get into the welcome page and if I click any of the links now, the 
> session of the request is not null and I can go to any links without any 
> problem. The null pointer did not occur in the following action class.
> 
> --If I close the browser then open browser again, I get NullPointerException 
> again if I repeat those steps.
> 
> What might be wrong?
> 
> Thanks so much in advance.
> 
> Angelina
> 
> 
> 
> -
> Yahoo! Sports
> Rekindle the Rivalries. Sign up for Fantasy Football
> 


-- 
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: http session lost between struts action

2005-06-23 Thread angelina zh
Michael,
 
Thank you so much for your reply. The login page is a JSP page. In the JSP 
page, the login form's mothod is post and the action is a struts action.
 
After login, we did some internal redircts for security checking and then take 
the user to the welcome page. The welcome page is generated from XML using 
xslt. 
 
We have a FrontController which extends ActionServlet from struts to handle 
request and response. I kept very close watching of the requests. I am very 
sure that the session has been established on the login page and kept valid 
till the welcome's action got invoked and the welcome page got constructed. 
After I clicked one of the links on the welcome page, I noticed that when the 
FrontController got invoked, the session had became to null. So we lost session 
before the next action class get invoked.
 
We can easier re-create the session object, but we lost the attributes we set 
in the last session. The following action classes will need those attriutes. 
 
I am wondering why the session keep valid if I login to the page again without 
closing browser. But the session get lost if I open another browser to log in. 
 
And another interesting thing is the session get lost in another place in the 
production enviroment.
 
I am not sure this is a tomcat issue or a struts issue.
 
Michael, any help will be greatly appreciated.
 
 


-
Yahoo! Sports
 Rekindle the Rivalries. Sign up for Fantasy Football

http session lost between struts action

2005-06-23 Thread angelina zh
Hi,
 
Can anyone please help me on this session lost issue?
 
Here is the problem I am getting:
 
-- If I open a IE 6.0 browser and log into the web site we are developing, I 
get into a welcome page with a few of link options. In the login action class, 
we set some attributes into the session. If I click on any of the links, I got 
null pointer exception in next action class when we try to get attributes from 
the session. I tried to use Eclipse to debug, noticed that the session of the 
request after the welcome page became to null.
 
--If I keep that browser open and go to the log in page again. After I log in, 
I get into the welcome page and if I click any of the links now, the session of 
the request is not null and I can go to any links without any problem. The null 
pointer did not occur in the following action class.
 
--If I close the browser then open browser again, I get NullPointerException 
again if I repeat those steps.
 
What might be wrong?
 
Thanks so much in advance.
 
Angelina



-
Yahoo! Sports
 Rekindle the Rivalries. Sign up for Fantasy Football