FileDocCategorySizeDatePackage
HelloNameServlet.javaAPI DocExample820Thu Apr 03 15:28:48 BST 1997None

HelloNameServlet

public class HelloNameServlet extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voidservice(ServletRequest request, ServletResponse response)


  service((HttpServletRequest) request, (HttpServletResponse) response);

public voidservice(HttpServletRequest request, HttpServletResponse response)


    String msg = "<HTML><BODY>";
    String name = request.getParameter("firstname");
    if (name != null) {
      msg += "Hello " + name;
    }
    else {
      msg += "Hello whoever you are.";
    }
    msg += "</BODY></HTML>";

    response.setContentLength(msg.length());
    response.setContentType("text/html");
    try {
      PrintStream rs = new PrintStream(response.getOutputStream());
      rs.print(msg);
    }
    catch (IOException e) {
    }