Setting and getting global attributes in servlets

B

Bruce Lee

If I start up a Jetty web application and set an attribute to the
HttpContext like so

server.getContext("/").setAttribute("objectname",obj);

How do I now get this attribute from a servlet?

Thanks
 
E

Ed

Bruce said:
If I start up a Jetty web application and set an attribute to the
HttpContext like so

server.getContext("/").setAttribute("objectname",obj);

How do I now get this attribute from a servlet?

Thanks

Haven't used Jetty meself, but for plain-ol' servlets it's:
HttpSession playerSession = httpServletRequest.getSession();
playerSession.setAttribute("objectname", obj);

And on the other side:
HttpSession playerSession = httpServletRequest.getSession();
Object obj = playerSession.getAttribute("objectname");

If Jetty offers the setAttribute() of the basic servlet but not the
getAttribute() then I'm sure there's a good reason for it ...

..ed
 
B

Bruce Lee

Ed said:
Haven't used Jetty meself, but for plain-ol' servlets it's:
HttpSession playerSession = httpServletRequest.getSession();
playerSession.setAttribute("objectname", obj);

And on the other side:
HttpSession playerSession = httpServletRequest.getSession();
Object obj = playerSession.getAttribute("objectname");

If Jetty offers the setAttribute() of the basic servlet but not the
getAttribute() then I'm sure there's a good reason for it ...

.ed

thanks for the reply. I'm looking at invoking an object at the top of the
server app and passing it down to the servlet level though. That'll work ok
for session but i want a permanent object I can control from the top.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top