JSP Implicit Objects

Implicit objects provide access to server side objects. The below are the implicit Objects available in JSP:
requesta  HttpServletRequest object passed to a Servlet. The accessibility of this request object is request scope. It can be used to access the request parameters, type, and header information. 
Example: request.getParameter(“username”) 

responsea HttpServletResponse object used by a Servlet. The scope of this object is within this page. It can be used to set the response headers and status

session: session associated with current request. An HttpSession object with session scope. session.setAttribute( key, data); session.getAttribute( key), and session.getId() are examples.

application: It represents the ServletContext obtained from servlet configuration object. You can set a attribute by application.setAttribute(key,value) and get the attribute value by application.getAttribute(key).  The application object has Application scope. 

pageContext: Object to access request, response, session and application associated with a page. An access point to all page attributes. getSession(), getRequest(), getResponse(), getOut() are some of its methods. The scope is in this page only. 

config: It represents the ServletConfig for the JSP. The JSP initialization parameters can be read via it. It has a page scope. 

out: Object that writes to the response output stream.A buffered JspWriter object that writes into the output stream. It can only be used by scriptlet element. out.println() is an often used example. The scope is page. 

page: instance of the page implementation class (this)

exception: Available with JSP pages which are error pages


<html>
  <head>
    <title>Implicit Objects</title>
  </head>
  <body>
    <p>
      Using Request parameters...<br>
      <b>Name:</b> <%= request.getParameter("name") %>
    </p>
    <p>
      <% out.println("This is printed using the out 
         implicit variable"); %>
    </p>
    <p>
      Storing a string to the session...<br>
      <% session.setAttribute("name", "Meeraj"); %>
      Retrieving the string from session...<br>
      <b>Name:</b> <%= session.getAttribute("name") %>
    </p>
     <p>
      Storing a string to the application...<br>
      <% application.setAttribute("name", "Meeraj"); %>
      Retrieving the string from application...<br>
      <b>Name:</b>
      <%= application.getAttribute("name") %>
    </p>
    <p>
      Storing a string to the page context...<br>
      <% pageContext.setAttribute("name", "Meeraj"); %>
      Retrieving the string from page context...</br>
      <b>Name:</b> 
      <%= pageContext.getAttribute("name") %>
    </p>
  </body>
</html>

Search: