// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.<P>
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.<P>
// 
// To obtain a copy of the GNU General Public License write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. <P>

import java.io.IOException ;
import java.io.PrintWriter ;

import javax.servlet.ServletException ;
import javax.servlet.http.* ;

/**
 * <code>HelloWorldServlet</code> simply displays "Hello World".
 *
 * @author <a href="mailto:rob@corwin.the-judds.org">Robert Judd</a>
 */
public class HelloWorldServlet extends HttpServlet {

    /**
     * In order to write a useful servlet you must implement at least one of
     * the methods <code>doGet</code> or <code>doPost</code>.  If you don't care
     * about the difference between GET and POST requests, then
     * you can just implement one, say doGet and then set the other to call it
     * (see <code>doPost</code> below).
     *
     * @param req a <code>HttpServletRequest</code> value
     * @param res a <code>HttpServletResponse</code> value
     * @exception ServletException if an error occurs
     * @exception IOException if an error occurs
     */
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    	throws ServletException, IOException {
	

	// You should set the content type of the response - the following lets
	// the browser know to expect an html page.  Any valid content type may
	// be returned, for example you can set it to "application/pdf" and write
	// a PDF file in response to the request.  If your browser knows about
	// PDF files, then it will run acroread or some other viewer to display
	// the file
	res.setContentType("text/html") ;

	// Next you must get the PrintWriter in order to output data
	PrintWriter out = res.getWriter() ;
	
	// Finally you can write any text to the stream
	out.println("<HTML><BODY><H1>Hello World!</H1></BODY></HTML>") ;

    }

    /**
     * Since this servlet is unlikely ever to be called with a POST request
     * (that is usually only done by forms) there is no need to implement this.
     * For other servlets, if the only POST requests come from HTML forms with
     * name=value pairs, then this method can simply call <code>doGet</code> as
     * shown below (commented out).  If you try to call this servlet with a POST
     * request, then you will get a "Bad Request" error from the server.
     *
     * I only usually bother implementing doPost if the data sent with the
     * request is more than just "name=value" pairs from a form - for example
     * a file, or a Java Object sent from an applet.
     *
     * @param req a <code>HttpServletRequest</code> value 
     * @param res a <code>HttpServletResponse</code> value
     * @exception ServletException if an error occurs
     * @exception IOException if an error occurs
     */
//      public void doPost(HttpServletRequest req, HttpServletResponse res)
//      	throws ServletException, IOException {
//  	doGet(req, res) ;
//      }

}// HelloWorldServlet
