JSP: storing Object to pageContext: old fashioned?

B

bruce_phipps

JSPs seem to offer more than one way of storing Objects to a session
context for session tracking purposes.

Both these seem to work Ok in my JSP code on Tomcat 5.0.x:

// using pageContext with session scope
pageContext.setAttribute("name", myObject, PageContext.SESSION_SCOPE);

// using the session context of HttpServlet
session.setAttribute("name",myObject);

Whats the difference here? Is there a preferred way to do this?

Thanks
Bruce
 
E

Erwin Moller

JSPs seem to offer more than one way of storing Objects to a session
context for session tracking purposes.

Both these seem to work Ok in my JSP code on Tomcat 5.0.x:

// using pageContext with session scope
pageContext.setAttribute("name", myObject, PageContext.SESSION_SCOPE);

// using the session context of HttpServlet
session.setAttribute("name",myObject);

Whats the difference here? Is there a preferred way to do this?

Thanks
Bruce

Hi Bruce,

Wrong newsgroup. :)
Your question is about J2EE, not JavaScript, so try comp.lang.java or
comp.lang.java.help instead.

To your question, my Javaskills are rotting a bit, but I think they are
identical, but setting the attribute directly on session makes a lot more
sense to me than doing it via PageContext.SESSIONSCOPE.

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top