session

The implicit session object holds a reference to a javax.servlet.http.HttpSession object. The HttpSession object is used to store objects in between client requests. It provides an almost state-full HTTP interactivity. The session object is initialized by a call to the pageContext.getSession() method in the generated servlet. The code snippet that initializes the session is as follows:

session = pageContext.getSession();

An example of using the implicit session object can be found in Listing 9.2.

Code Listing 9.2. UseSession.jsp
<%@ page errorPage="errorpage.jsp" %>

<html>
  <head>
    <title>UseSession</title>
  </head>
  <body>
    <%
      // Try and get the current count from the session
      Integer count = (Integer)session.getAttribute("COUNT"); // ...

Get Pure Java Server Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.