request.getSession().getAttribute() and session.getAttribute()

Hi All,

Sorry guys, I'm a novice in web programming and this may sound like a stupid question to you guys... Here it goes...

Is there any difference between request.getSession().getAttribute() and session.getAttribute()?

I have tried doing the following in PAGE1:-

session.setAttribute("TEXT","novice");

objRequestDispatcher = request.getRequestDispatcher(PAGE2);

objRequestDispatcher.forward(request, response);

When in PAGE2, I'm able to get contents of "TEXT" by doing:-

request.getSession().getAttribute("TEXT");

1) so doessession andrequest.getSession() refers to the same object?

Can i do asession.getAttribute("TEXT") to get the contents too?

2) And if I have a PAGE3, am I able to retrieve contents of "TEXT" which is set in

PAGE1?

3) And also will I be able to get the contents of "TEXT" if I'm doing a

window.open() to go from PAGE1 to PAGE2?

I have tried to find out the answers by "try and error" but the more I tried the more confused I get...

Hope that someone can give me some advice.

Thanks in Advance.

[1219 byte] By [redders83a] at [2007-10-1 0:41:11]
# 1

Hi

> 1) so does session and

> request.getSession() refers to the same

> object?

Yes, session is just a conveniance variable in JSPs.

> 2) And if I have a PAGE3, am I able to retrieve

> contents of "TEXT" which is set in

>PAGE1?

Yes, as long as same session is used.

> 3) And also will I be able to get the contents of

> "TEXT" if I'm doing a

> window.open() to go from PAGE1 to

> 1 to PAGE2?

My experience is that window.open() may lead to a new session being created. It may be good to specify session ID in new window URL to be sure the same session will be used.

Basically, the session persists for a specified time period (defined in your web app configuration file), across more than one connection or page request from the user.

If a session is expired (or has been invalidated) when making a request, a new session will be created. This new session will be empty, so your session data will be lost (you can check this case with session.isNew().)

TimTheEnchantora at 2007-7-8 0:55:43 > top of Java-index,Security,Event Handling...
# 2
Hi Tim...Thanks for your prompt reply..How about document.form1.submit()?Any idea whether this will create a session?Thanks
redders83a at 2007-7-8 0:55:43 > top of Java-index,Security,Event Handling...
# 3
> How about document.form1.submit()?> Any idea whether this will create a session?Form submission is a standard case of user request. Session will remain.
TimTheEnchantora at 2007-7-8 0:55:43 > top of Java-index,Security,Event Handling...
# 4
thanks a lot for your clarifications..
redders83a at 2007-7-8 0:55:43 > top of Java-index,Security,Event Handling...