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

Info icon This 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>
Image of page 1

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

View Full Document Right 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); } }
Image of page 2
Listing 16.4 EmployeeBean.java package coreservlets; public class EmployeeBean { private NameBean name; private CompanyBean company;
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern