JSP Servlet shared bean example: Difference between revisions

From sheep
Jump to navigation Jump to search
(Created page with "Servlet code: public void doRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ HttpSession session = req...")
 
(No difference)

Latest revision as of 21:30, 14 September 2021

Servlet code:

public void doRequest(HttpServletRequest req,
                   HttpServletResponse res) throws ServletException, IOException{
     HttpSession session = req.getSession();
     FooBean foo= new FooBean ;
     foo.setName("FooBean", "bar");
     session.setAttribute("FooBean", foo);

JSP code

<jsp:useBean id="foo" type="FooBean" scope="session"/>
<jsp:getProperty name="foo" property="name"/>