servlet api
Servlet API (Servlet API)
Servlet API consists of two important packages that encapsulates all the important classes and interface, namely :
Servlet API由两个重要的程序包组成,它们封装了所有重要的类和接口,即:
- javax.servletjavax.servlet
- javax.servlet.httpjavax.servlet.http
javax.servlet一些重要类和接口 (Some Important Classes and Interfaces of javax.servlet)
| INTERFACES | CLASSES |
|---|---|
| Servlet | ServletInputStream |
| ServletContext | ServletOutputStream |
| ServletConfig | ServletRequestWrapper |
| ServletRequest | ServletResponseWrapper |
| ServletResponse | ServletRequestEvent |
| ServletContextListener | ServletContextEvent |
| RequestDispatcher | ServletRequestAttributeEvent |
| SingleThreadModel | ServletContextAttributeEvent |
| Filter | ServletException |
| FilterConfig | UnavailableException |
| FilterChain | GenericServlet |
| ServletRequestListener |
| 介面 | 类 |
|---|---|
| Servlet | ServletInputStream |
| ServletContext | ServletOutputStream |
| ServletConfig | ServletRequestWrapper |
| Servlet请求 | ServletResponseWrapper |
| ServletResponse | ServletRequestEvent |
| ServletContextListener | ServletContextEvent |
| RequestDispatcher | ServletRequestAttributeEvent |
| 单线程模型 | ServletContextAttributeEvent |
| 过滤 | ServletException |
| FilterConfig | UnavailableException |
| 过滤链 | 通用Servlet |
| ServletRequestListener |
javax.servlet.http一些重要类和接口 (Some Important Classes and Interface of javax.servlet.http)
| CLASSES and INTERFACES | |
|---|---|
| HttpServlet | HttpServletRequest |
| HttpServletResponse | HttpSessionAttributeListener |
| HttpSession | HttpSessionListener |
| Cookie | HttpSessionEvent |
| 类和接口 | |
|---|---|
| HttpServlet的 | HttpServletRequest |
| HttpServletResponse | HttpSessionAttributeListener |
| HttpSession | HttpSessionListener |
| 曲奇饼 | HttpSessionEvent |
Servlet接口 (Servlet Interface)
Servlet Interface provides five methods. Out of these five methods, three methods are Servlet life cycle methods and rest two are non life cycle methods.
Servlet接口提供了五种方法。 在这五种方法中,三种方法是Servlet生命周期方法,其余两种是非生命周期方法。
GenericServlet类 (GenericServlet Class)
GenericServlet is an abstract class that provides implementation of most of the basic servlet methods. This is a very important class.
GenericServlet是一个抽象类,提供大多数基本Servlet方法的实现。 这是非常重要的一类。
Methods of GenericServlet class
GenericServlet类的方法
-
public void init(ServletConfig)public void init(ServletConfig) -
public abstract void service(ServletRequest request,ServletResposne response)public abstract void service(ServletRequest request,ServletResposne response) -
public void destroy()public void destroy() -
public ServletConfig getServletConfig()public ServletConfig getServletConfig() -
public String getServletInfo()public String getServletInfo() -
public ServletContext getServletContext()public ServletContext getServletContext() -
public String getInitParameter(String name)public String getInitParameter(String name) -
public Enumeration getInitParameterNames()public Enumeration getInitParameterNames() -
public String getServletName()public String getServletName() -
public void log(String msg)public void log(String msg) -
public void log(String msg, Throwable t)public void log(String msg, Throwable t)
HttpServlet类 (HttpServlet class)
HttpServlet is also an abstract class. This class gives implementation of various service() methods of Servlet interface.
HttpServlet也是一个抽象类。 此类提供了Servlet接口的各种service()方法的实现。
To create a servlet, we should create a class that extends HttpServlet abstract class. The Servlet class that we will create, must not override service() method. Our servlet class will override only the doGet() and/or doPost() methods.
要创建servlet,我们应该创建一个扩展HttpServlet抽象类的类。 我们将创建的Servlet类不得覆盖service()方法。 我们的Servlet类将仅覆盖doGet()和/或doPost()方法。
The service() method of HttpServlet class listens to the Http methods (GET, POST etc) from request stream and invokes doGet() or doPost() methods based on Http Method type.
HttpServlet类的service()方法从请求流中侦听Http方法(GET,POST等),并基于Http方法类型调用doGet()或doPost()方法。
servlet api