servlet api_Servlet API

本文详细介绍了Servlet API的构成,包括其核心的javax.servlet和javax.servlet.http包中的关键类和接口。探讨了Servlet接口的五种方法,以及GenericServlet和HttpServlet类的重要性和使用方式。

servlet api

Servlet API consists of two important packages that encapsulates all the important classes and interface, namely :

Servlet API由两个重要的程序包组成,它们封装了所有重要的类和接口,即:

  • javax.servlet

    javax.servlet

  • javax.servlet.http

    javax.servlet.http

javax.servlet一些重要类和接口 (Some Important Classes and Interfaces of javax.servlet)

INTERFACESCLASSES
ServletServletInputStream
ServletContextServletOutputStream
ServletConfigServletRequestWrapper
ServletRequestServletResponseWrapper
ServletResponseServletRequestEvent
ServletContextListenerServletContextEvent
RequestDispatcherServletRequestAttributeEvent
SingleThreadModelServletContextAttributeEvent
FilterServletException
FilterConfigUnavailableException
FilterChainGenericServlet
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
HttpServletHttpServletRequest
HttpServletResponseHttpSessionAttributeListener
HttpSessionHttpSessionListener
CookieHttpSessionEvent
类和接口
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生命周期方法,其余两种是非生命周期方法。

Servlet interface example

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()方法。

Httpservlet Api and creating first Servlet Class

翻译自: https://www.studytonight.com/servlet/servlet-api.php

servlet api

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值