Listing 16 - Listing 16.1 ScopedVars.java package...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Listing 16.1 ScopedVars.java package coreservlets; /** Servlet that creates some scoped variables (objects stored * as attributes in one of the standard locations). Forwards * to a JSP page that uses the expression language to * display the values. */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class ScopedVars extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("attribute1", "First Value"); HttpSession session = request.getSession(); session.setAttribute("attribute2", "Second Value"); ServletContext application = getServletContext(); application.setAttribute("attribute3", new java.util.Date()); request.setAttribute("repeated", "Request"); session.setAttribute("repeated", "Session"); application.setAttribute("repeated", "ServletContext"); RequestDispatcher dispatcher = request.getRequestDispatcher("/el/scoped-vars.jsp"); dispatcher.forward(request, response); } } Listing 16.2 scoped-vars.jsp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE>Accessing Scoped Variables</TITLE> <LINK REL=STYLESHEET HREF="/el/JSP-Styles.css" TYPE="text/css"> </HEAD>
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
<BODY> <TABLE BORDER=5 ALIGN="CENTER"> <TR><TH CLASS="TITLE"> Accessing Scoped Variables </TABLE> <P> <UL> <LI><B>attribute1:</B> ${attribute1} <LI><B>attribute2:</B> ${attribute2} <LI><B>attribute3:</B> ${attribute3} <LI><B>Source of "repeated" attribute:</B> ${repeated} </UL> </BODY></HTML> Listing 16.3 BeanProperties.java package coreservlets; /** Servlet that creates some beans whose properties will * be displayed with the JSP 2.0 expression language. */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class BeanProperties extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { NameBean name = new NameBean("Marty", "Hall"); CompanyBean company = new CompanyBean("coreservlets.com", "J2EE Training and Consulting"); EmployeeBean employee = new EmployeeBean(name, company); request.setAttribute("employee", employee); RequestDispatcher dispatcher = request.getRequestDispatcher("/el/bean- properties.jsp"); dispatcher.forward(request, response); } }
Background image of page 2
Listing 16.4 EmployeeBean.java package coreservlets; public class EmployeeBean { private NameBean name; private CompanyBean company; public EmployeeBean(NameBean name, CompanyBean company) { setName(name); setCompany(company); } public NameBean getName() { return(name); } public void setName(NameBean newName) {
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course MATH 401 taught by Professor H.ayad during the Spring '11 term at Cairo University.

Page1 / 11

Listing 16 - Listing 16.1 ScopedVars.java package...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online