package cs320.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/DisplayCounter") public class DisplayCounter extends HttpServlet { private static final long serialVersionUID = 1L; public DisplayCounter() { super(); } protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { ServletContext servletContext = getServletContext(); // get the counter Integer counter = (Integer) servletContext.getAttribute( "counter" ); // display the message "the counter is incremented" PrintWriter out = response.getWriter(); response.setContentType( "text/html" ); out.println( "Display Counter" ); out.println( "

The counter value is currently: " + counter + "

" ); out.println( "" ); } }