import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

/*
 * Name -- function
 * 
 * @author  YOURNAME
 * @version $Id$
 */
public class Servlet extends HttpServlet
{
	/** Called in response to a GET request (data encoded in the URL) */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

		ServletContext application = getServletContext();

		// to do: logic code and main HTML goes HERE.
		// ...

		// Output section in MVC: dispatch to JSP to display the work.
		// (Remember the URL for an RD **MUST** be absolute).
		RequestDispatcher rd = application.getRequestDispatcher("/foo.jsp");
		rd.forward(request, response);

		// ALTERNATE Output section IF this servlet displays output itself
		response.setContentType("text/html");
		PrintWriter out = response.getWriter(); 

		out.println("<!DOCTYPE html PUBLIC " +
			"\"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" +
			"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"\n" +
			">");
		out.println("<html>");
		out.println("<head><title>Servlet Output</title></head>");
		out.println("<body>");

		// to do: output results of work here

		// BOILERPLATE ending
		out.println("</body>");
		out.println("</html>");
		out.flush();

	}

	/** Called in response to a POST request (data unencoded on the socket) */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

		// One of the following:

		// Delegate to doGet:
		// doGet(request, response);

		ServletContext application = getServletContext();

		// Alternate Version: Do work different than that of doGet
		response.setContentType("text/html");
		PrintWriter out = response.getWriter(); 

		// BOILERPLATE beginning
		out.println("<!DOCTYPE html PUBLIC " +
			"\"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" +
			"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"\n" +
			">");

		out.println("<html>");
		out.println("<head><title>Servlet Output</title></head>");
		out.println("<body>");

		// to do: logic code and main HTML goes here.

		// BOILERPLATE ending
		out.println("</body>");
		out.println("</html>");
		out.flush();
	}
}
