Accessing HTTP Servlet Variables

The JSP pages you write are translated into servlets that process the HTTP GET and POST requests. The JSP code can access servlet information using implicit objects defined for each page. These implicit objects are pre-declared variables that you reference from the Java code on your JSP. The most commonly used objects are shown in Table 13.3.

Table 13.3. JSP Implicit Objects
Reference NameClassDescription
configjavax.servlet.ServletConfigThe servlet configuration information for the page
requestsubclass of javax.servlet.ServletRequestRequest information for the current HTTP request
sessionjavax.servlet.http.HttpSessionThe servlet session object for the client
outjavax.servlet.jsp.JspWriterA subclass of java.io.Writer that is used to output text for inclusion on the Web page
pageContextjavax.servlet.jsp.PageContextThe JSP page context used primarily when implementing custom tags (see Day 14)
applicationjavax.servlet.ServletContextThe context for all Web components in the same application

The following example rather laboriously writes the value of the name request parameter to the Web page and is another variant of the examples shown in Listings 13.1 and 13.2.

<HTML>
  <HEAD><TITLE>Hello</TITLE></HEAD>
  <BODY>
    <H1>Hello <% out.print(request.getParameter("name")); %></H1>
  </BODY>
</HTML>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.170.187