package cn.sasa.serv; import java.io.IOException; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletResponse; public class QuickStart implements Servlet{ @Override public void init(ServletConfig config) throws ServletException { //对象创建时执行 //默认第一次访问时创建 System.out.println("init......"); //获取servlet-name String name = config.getServletName(); System.out.println(name); //获取初始化参数 String paramId = config.getInitParameter("id"); System.out.println(paramId); //ServletContext对象 ServletContext context = config.getServletContext(); } @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { //每次访问都执行 System.out.println("service......"); HttpServletResponse resp = (HttpServletResponse)res; resp.getWriter().write("hi");; } @Override public void destroy() { //销毁 System.out.println("destroy......."); } @Override public ServletConfig getServletConfig() { //配置信息 return null; } @Override public String getServletInfo() { return null; } }