JAVA WEB开发 (First Servlet Samlet Code) 第四天

JAVA WEB开发 (First Servlet Samlet Code) 第四天

HelloServlet.java

package tw.com.javaworld.CH2;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class HelloServlet extends HttpServlet{
    //Initialize global variables
    public void init(ServletConfig config) throws ServletException{
        super.init(config);
    }
    
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=GB2312");
        PrintWrite out = response.getWrite();
        out.println("<html>");
        out.println("<body>");
        out.println("Hello World<br>");
        out.println("大家好");
        out.println("</body>");
        out.println("</html>");
        out.close();
    }

    //Get Servlet information
    public String getServletInfo(){
        return "tw.com.javaworld.CH2.HelloServlet Information";
    }
}



你可能感兴趣的:(JAVA WEB开发 (First Servlet Samlet Code) 第四天)