01: /*
02: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: */
07: package winstone.testApplication.servlets;
08:
09: import java.io.IOException;
10:
11: import javax.servlet.ServletException;
12: import javax.servlet.ServletOutputStream;
13: import javax.servlet.http.HttpServlet;
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletResponse;
16:
17: /**
18: * Simple test servlet that counts the number of times it has been requested,
19: * and returns that number in the response.
20: *
21: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
22: * @version $Id: CountRequestsServlet.java,v 1.3 2006/02/28 07:32:49 rickknowles Exp $
23: */
24: public class CountRequestsServlet extends HttpServlet {
25: private int numberOfGets;
26:
27: public void init() {
28: String offset = getServletConfig().getInitParameter("offset");
29: numberOfGets = offset == null ? 0 : Integer.parseInt(offset);
30: }
31:
32: /**
33: * Get implementation - increments and shows the access count
34: */
35: protected void doGet(HttpServletRequest request,
36: HttpServletResponse response) throws ServletException,
37: IOException {
38: numberOfGets++;
39: ServletOutputStream out = response.getOutputStream();
40: out
41: .println("<html><body>This servlet has been accessed via GET "
42: + numberOfGets + " times</body></html>");
43: out.flush();
44: }
45: }
|