简体   繁体   中英

How to retrieve one servlet session attributes in another servlet

I have two servlets in my project 2nd being called from the 1st servlet. Im creating http session in first servlet and setting some attributes to that session object. How do i get the values of these attributes in second servlet?

Thanks in advance.

Object value = request.getSession().getAttribute("nameOfTheAttributeUsedInTheFirstServlet");

If two servlets are in the same webapp, they share the same session context, and the session is the same for both servlets. Of course, remember that a session is tight to a particular user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM