JSP Servlet shared bean example

From sheep
Revision as of 21:30, 14 September 2021 by Martin (talk | contribs) (Created page with "Servlet code: public void doRequest(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ HttpSession session = req...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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"/>