Servlet中的ServletRequestEvent和ServletRequestListener

ServletRequestEvent class gives notification about lifecycle events for a ServletRequest. The source of the event is the ServletContext of the web application. ServletRequestListener receives the notifications generated by ServletRequestEvent and performs some specified tasks based on them.

ServletRequestEvent类提供有关ServletRequest生命周期事件的通知。 事件的源是Web应用程序的ServletContext。 ServletRequestListener接收ServletRequestEvent生成的通知,并根据这些通知执行一些指定的任务。

ServletRequestListener的一些重要方法 (Some Importants Methods of ServletRequestListener)

MethodsDescription
void requestDestroyed(ServletRequestEvent e)is invoked when request is about to go out of scope of the web application..
void requestInitialized(ServletRequestEvent e)is invoked when request is about to come into scope of the web application.
方法 描述
void requestDestroyed(ServletRequestEvent e) 当请求将超出Web应用程序的范围时调用。
void requestInitialized(ServletRequestEvent e) 当请求即将进入Web应用程序范围时调用。

ServletRequestListener的示例 (Example for ServletRequestListener)

ServletRequestListener example

Hence one can easily implement the ServletRequestListener Interface and provide definitions to the two methods provided by it, requestDestroyed() and requestInitialized().

因此,可以轻松实现ServletRequestListener接口,并为其定义的两个方法requestDestroyed()requestInitialized()提供定义。

As the name suggests these methods will be called when request is initialized and when it is destroyed, hence we can use them for various purposes, like variable cleanup when request is destroyed, or performing some initial checks when request is received etc.

顾名思义,这些方法将在初始化请求和销毁请求时调用,因此我们可以将它们用于各种目的,例如销毁请求时进行变量清理 ,或在收到请求时执行一些初始检查等。

翻译自: https://www.studytonight.com/servlet/servlet-request-event-and-listener.php

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值