import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletContextAttribute extends HttpServlet
{
	public void doGet(HttpServletRequest req, HttpServletResponse res)
	throws IOException,ServletException
	{
		res.setContentType("text/html");
		PrintWriter pw = res.getWriter();
  HttpSession session = req.getSession(true);
  Integer count = 
	  (Integer) getServletContext().getAttribute("total");
	  if (count == null)
	  {
		  count = new Integer(1);
	  }
	  else
	  {
		  count = new Integer(count.intValue() + 1);
	  }
	  getServletContext().setAttribute("total", count);
  pw.println
("<html><head><title>Context Attribute</title></head>");
  pw.println
("<h1>Session Details:</h1>");
  pw.println
 ("Time of the Session Created: " + new Date(session.getCreationTime())
 + "<br/>");
  pw.println
("Last time accessed : " + new Date(session.getLastAccessedTime()) 
+ "<br/>");
  pw.println("You are visiting "+ count+" time");
  pw.println("</body></html>");
  }
}