站点图标 度崩网-几度崩溃

servlet的常用方法

javax.servlet.Servlet 接口定义 servlet 的标准,下面是 3.0.1 版 Servlet 接口中的方法:

//初始化public void init(ServletConfig config) throws ServletException;//返回 servlet 初始化信息与启动参数public ServletConfig getServletConfig();//被 servlet 容器调用,响应 servlet 请求public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException;//返回 servlet 信息,如作者、版本和版权public String getServletInfo();//由 servlet 容器调用,把 servlet 去除public void destroy();

javax.servlet.Servlet.GenericServlet 抽象类实现了 javax.servlet.Servlet,并无具体实现。

javax.servlet.http.HttpServlet 抽象类继承了 javax.servlet.Servlet.GenericServlet。HttpServlet 类中的 service() 方法根据 http 的 method 类型分别请求了如下方法

protected void doGet(HttpServletRequest req, HttpServletResponse resp)protected void doPost(HttpServletRequest req, HttpServletResponse resp)protected void doHead(HttpServletRequest req, HttpServletResponse resp)protected void doPut(HttpServletRequest req, HttpServletResponse resp)protected void doDelete(HttpServletRequest req, HttpServletResponse resp)protected void doOptions(HttpServletRequest req, HttpServletResponse resp)protected void doTrace(HttpServletRequest req, HttpServletResponse resp)