I create a java bean in the session scope using <jsp:useBean> in a JSP page. I then need to access the information held by the bean in a servlet. How can I get hold of the bean in the servlet? |
Answer: The JSP session scope corresponds to the javax.servlet.http.HttpSession class in the Servlet API. The session scope objects are saved as attributes for the current instance of this class, so you can get them with code like this in a servlet: HttpSession session = request.getSession(); String foo = (String) session.getAttribute("foo"); For more information about how to share objects between JSP pages and servlets, see Chapter 14 in the book. |
Very useful and interesting. Thankyou for sharing this Great article