package cs3220.controller; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cs3220.model.GuestBookEntry; @WebServlet("/AddComment") public class AddComment extends HttpServlet { private static final long serialVersionUID = 1L; private static int idSeed = 100; public AddComment() { super(); } protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { request.getRequestDispatcher( "/WEB-INF/AddComment.jsp" ) .forward( request, response ); } @SuppressWarnings("unchecked") protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { List entries = (List) getServletContext() .getAttribute( "entries" ); entries .add( new GuestBookEntry( idSeed++, request.getParameter( "name" ), request.getParameter( "message" ) ) ); response.sendRedirect( "GuestBook" ); } }