The Counter Servlet Revisited
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;
public class Counter extends HttpServlet {
int count = 0 ;
public void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws IOException, ServletException {
resp.setContentType(“text/html”) ;
PrintWriter out = resp.getWriter() ;
out.println(“<html><head></head><body>”) ;
out.println(“This servlet instance has been accessed ” +
(count++) + “ times”) ;
out.println(“ </body></html>”) ;
}
}