01 package interval;
02
03 import java.io.*;
04 import javax.servlet.*;
05 import javax.servlet.http.*;
06
07 public class SimpleCounter extends HttpServlet {
08
09 private int calledCount;
10
11 public void init(ServletConfig config) throws ServletException {
12 super.init(config);
13 calledCount = 0;
14 }
15
16 protected void service(HttpServletRequest req, HttpServletResponse res)
17 throws ServletException, IOException {
18 res.setContentType("text/html");
19 PrintWriter out = res.getWriter();
20 out.println("<HTML><BODY>");
21 out.println("<H2>Servlet API Example - SimpleCounter</H2><HR>");
22 ++calledCount;
23 out.println("<H4>This servlet has been called: " + calledCount +
24 " times.</H4>");
25 out.println("</BODY><HTML>");
26 out.close();
27 }
28 }
|