Servlet API:Servlet接口

image.png

提示已存在检查web.xml中是否已经存在

    
        
        
        HelloServlet
        HelloServlet
        com.baozi.HelloServlet
    
    
        HelloServlet
        /HelloServlet
    
package com.baozi;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Servlet implementation class HelloServlet
 */
public class HelloServlet implements Servlet{

    /**
     * Default constructor. 
     */
    public HelloServlet() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see Servlet#init(ServletConfig)
     */
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
    }

    /**
     * @see Servlet#destroy()
     */
    public void destroy() {
        // TODO Auto-generated method stub
    }

    /**
     * @see Servlet#getServletConfig()
     */
    public ServletConfig getServletConfig() {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * @see Servlet#getServletInfo()
     */
    public String getServletInfo() {
        // TODO Auto-generated method stub
        return null; 
    }

    /**
     * @see Servlet#service(ServletRequest request, ServletResponse response)
     */
    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        PrintWriter pwt=response.getWriter();
        pwt.println("Hello Servlet!");
        pwt.close();
    }

}

image.png

你可能感兴趣的:(Servlet API:Servlet接口)