Example Servlet
import javax.servlet.http.*;
* HelloWorldServlet sends back a simple,
public class HelloWorldServlet extends HttpServlet
HttpServletRequest req, // This provides //information
HttpServletResponse res // This is used to send //information
) throws ServletException, IOException
// that should be thrown if there
// is a unrecoverable error in the Servlet
// Set the MIME type for the information being sent to the browser.
// In this case, we are going to send back HTML
res.setContentType( "text/html" );
// Get a reference to the output stream.
// Anything written to this stream is sent directly
// (The browser sees this as its input).
ServletOutputStream out = res.getOutputStream();
// The following println statements create an //HTML page.
// Notice that the <html></html>, <head></head>, //and <body></body>
// tags are all properly formed HTML syntax.
out.println( "<head><title>Hello World</title></head>" );
out.println( "<h1>Hello World</h1>" );
out.println( "<p>Congratulations, your first servlet is working!</p>" );
out.println( "</body>" );
out.println( "</html>" );