首页 > 代码库 > java/Servlet

java/Servlet

 1 package cn.web.servlet; 2  3 import java.io.IOException; 4 import java.util.Enumeration; 5  6 import javax.servlet.Servlet; 7 import javax.servlet.ServletConfig; 8 import javax.servlet.ServletException; 9 import javax.servlet.ServletRequest;10 import javax.servlet.ServletResponse;11 /**12  * Servlet方法解说13  */14 public class AServlet implements Servlet {15     16     /**17      * 他是声明周期方法18      *         他会在servlet被销毁之前调用:并且他只会被调用一次:19      */20     @Override21     public void destroy() {22         System.out.println("destroy.....");23     }24     /**25      * 用来获取servlet配置信息26      */27     @Override28     public ServletConfig getServletConfig() {29         System.out.println("getServletConfig.....");30         return null;31     }32     /**33      * 用来获取servlet信息34      *         爱运行不运行 35      */36     @Override37     public String getServletInfo() {38         System.out.println("getServletInfo.....");39         return "我是一个快乐的servlet";40     }41 42     /**43      * 他是声明周期方法44      *         他会在servlet对像创立之后马上执行,并只执行一次;(出生之后)45      */46     @Override47     public void init(ServletConfig ServletConfig) throws ServletException {48         System.out.println("init.....");49         /**50          * 获取初始化参数51         */52         System.out.println(ServletConfig.getInitParameter("p1"));53         System.out.println(ServletConfig.getInitParameter("p2"));54         /**55          * 获取所有初始化的值56          */57         Enumeration<?> e = ServletConfig.getInitParameterNames();58         while (e.hasMoreElements()) {59             System.out.println(e.nextElement());60         }61     }62     /**63      * 他是声明周期方法64      *         它会被调用多次,每次处理请求都在用这个方法:65      */66     @Override67     public void service(ServletRequest ServletRequest, ServletResponse ServletResponse)68             throws ServletException, IOException {69         System.out.println("service.....");70     }71 }

 

java/Servlet