Codul sursa pentru SimpleCounterServlet.java
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SimpleCounterServlet extends HttpServlet { private static final long serialVersionUID = 1L; int count = 0; public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { int localCounter; res.setContentType("text/plain"); PrintWriter out = res.getWriter(); synchronized(this) { localCounter = count++; } out.println("Servlet was used for " + localCounter + " times."); } }