如何获得一个servlet与另一个servlet的会话属性?
问题描述:
你好,
我有三个servlet,一个在另一个servlet中被调用.我在第一个servlet中创建一个http会话并为其设置一些属性.我想在第二和第三小服务程序中获取这些属性.我怎样才能做到这一点?请提出一种方法并提供适当的语法.
在此先感谢.
Hello,
I have three servlets one being called from within another.Im creating a http session in first servlet and setting some attributes for it. I want to getthose attributes in second and thirdservlets. How can i do that? Please suggest a way and give appropriate syntax.
Thanks in advance.
答
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.
Object value = request.getSession().getAttribute("nameOfTheAttributeUsedInTheFirstServlet");