1 PackageCn.yzu;2 Importjava.io.IOException;3 ImportJava.io.PrintWriter;4 ImportJavax.servlet.ServletContext;5 Importjavax.servlet.ServletException;6 ImportJavax.servlet.http.HttpServlet;7 Importjavax.servlet.http.HttpServletRequest;8 ImportJavax.servlet.http.HttpServletResponse;9 Ten Public classAservletextendsHttpServlet { One A Public voiddoget (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { -ServletContext application= This. Getservletcontext (); theInteger count= (integer) application.getattribute ("Count"); - if(count==NULL) - { -Count=1; +Application.setattribute ("Count", count); - } + Else AApplication.setattribute ("Count", + +count); atPrintWriter writer=Response.getwriter (); -Writer.print ("); - } - Public voidDoPost (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { - doget (request, response); in } -}
View Code
Servlet domain object ServletContext Small app------calculate site visits