FileDocCategorySizeDatePackage
ContextAccessor.javaAPI DocExample1109Fri Feb 13 07:43:42 GMT 2004com.jspservletcookbook

ContextAccessor

public class ContextAccessor extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

    
    //get a servlet context attribute
    ContextObject contextObj = (ContextObject)
   getServletContext().getAttribute(
        "com.jspservletcookbook.ContextObject");
        
        if (contextObj != null)
            contextObj.put(request.getRemoteAddr(),""+new java.util.Date());
        
    //display 
      response.setContentType("text/html");
      java.io.PrintWriter out = response.getWriter();
      out.println("<html><head><title>Servlet Context Attribute</title></head><body>");
      if (contextObj != null){
      out.println("<h2>Servlet Context Attribute Values</h2>");
      out.println(contextObj.getValues());
      } else {
       out.println("<h2>Servlet Context Attribute is Null</h2>");
      }
      out.println("</body></html>");