What is the HelloWorld Servlet?
Created Sep 3, 1999
Alex Chaffee
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class HelloHttpServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
String name = req.getParameter("name");
if (name == null) name = "Joe";
res.setContentType("text/plain");
ServletOutputStream out = res.getOutputStream();
out.println("Hello, " + name + "!");
}
}
This code responds to an invocation of the form
http://myserver.foo.com/servlet/HelloHttpServlet?name=Fred