tw.com.javaworld.CH2.HelloServlet (Java2HTML)

| HelloServlet.java |

    1 package tw.com.javaworld.CH2;
    2
    3 import javax.servlet.*;
    4 import javax.servlet.http.*;
    5 import java.io.*;
    6
    7 public class HelloServlet extends HttpServlet {
    8
    9     //Initialize global variables
    10    public void init(ServletConfig config) throws ServletException {
    11        super.init(config);
    12    }
    13
    14    //Process the HTTP Get request
    15    public void doGet(HttpServletRequest request, HttpServletResponse response)
    16        throws ServletException, IOException {
    17        response.setContentType("text/html");
    18        PrintWriter out = response.getWriter();
    19
    20        out.println("<html>");
    21        out.println("<head><title>CH2 - HelloServlet</title></head>");
    22        out.println("<body>");
    23        out.println(" Hello World <br>");
    24        out.println("¤j®a¦n");
    25        out.println("</body>");
    26        out.println("</html>");
    27
    28        out.close();
    29    }
    30
    31    //Get Servlet information
    32    public String getServletInfo() {
    33        return "tw.com.javaworld.CH2.HelloSerlvet Information";
    34    }
    35}