当前位置: 首页 > news >正文

做网站开发使用百分比的好处推广神器app

做网站开发使用百分比的好处,推广神器app,广西最新一批违法领导,嘉兴网站制作软件一、什么是监听器 servlet监听器是一种特殊的接口,用于监听特定的事件(如请求创建和销毁、会话创建和销毁、上下文的初始化和销毁)。 当Web应用程序中反生特定事件时,Servlet容器就会自动调用监听器中相应的方法来处理这些事件。…

一、什么是监听器

servlet监听器是一种特殊的接口,用于监听特定的事件(如请求创建和销毁、会话创建和销毁、上下文的初始化和销毁)。

当Web应用程序中反生特定事件时,Servlet容器就会自动调用监听器中相应的方法来处理这些事件。

二、监听器的作用?

1、全局初始化和清理

通过实现ServletContextListener接口,开发者可以在Web应用程序启动时执行全局初始化操作(例如加载配置文件、初始化数据库连接池等),并在应用程序关闭时执行清理操作(例如关闭数据库连接池、释放资源等)。

public class MyServletContextListener implements ServletContextListener {@Overridepublic void contextInitialized(ServletContextEvent sce) {// 应用程序初始化时执行的代码System.out.println("Application is starting...");}@Overridepublic void contextDestroyed(ServletContextEvent sce) {// 应用程序销毁时执行的代码System.out.println("Application is shutting down...");}
}

2、会话管理

通过实现HttpSessionListener接口,开发者可以监控用户会话的创建和销毁。这可以用于统计当前在线用户数量、清理过期会话等。

public class MyHttpSessionListener implements HttpSessionListener {private int activeSessions = 0;@Overridepublic void sessionCreated(HttpSessionEvent se) {activeSessions++;System.out.println("Session created. Total active sessions: " + activeSessions);}@Overridepublic void sessionDestroyed(HttpSessionEvent se) {activeSessions--;System.out.println("Session destroyed. Total active sessions: " + activeSessions);}
}

3、请求和属性监听

通过实现ServletRequestListenerServletRequestAttributeListener接口,开发者可以监听请求的生命周期以及请求属性的变化。这可以用于日志记录、性能监控或动态修改请求属性等。

public class MyServletRequestListener implements ServletRequestListener {@Overridepublic void requestInitialized(ServletRequestEvent sre) {System.out.println("Request initialized...");}@Overridepublic void requestDestroyed(ServletRequestEvent sre) {System.out.println("Request destroyed...");}
}

三、监听器的种类?

1)ServletRequestListener

用途:监听 ServletRequest 的创建和销毁事件。

方法:

  • void requestInitialized(ServletRequestEvent sre):在请求初始化时被调用。

  • void requestDestroyed(ServletRequestEvent sre):在请求销毁时被调用。

代码:

public class MyServletRequestListener implements ServletRequestListener {@Overridepublic void requestInitialized(ServletRequestEvent sre) {System.out.println("Request initialized");}@Overridepublic void requestDestroyed(ServletRequestEvent sre) {System.out.println("Request destroyed");}
}

 

2) ServletRequestAttributeListener

用途监听 ServletRequest 中属性的添加、修改和删除事件。

方法:

  • void attributeAdded(ServletRequestAttributeEvent srae):当属性被添加到请求时调用。

  • void attributeRemoved(ServletRequestAttributeEvent srae):当属性从请求中移除时调用。

  • void attributeReplaced(ServletRequestAttributeEvent srae):当请求中的属性被替换时调用。

代码:

public class MyServletRequestAttributeListener implements ServletRequestAttributeListener {@Overridepublic void attributeAdded(ServletRequestAttributeEvent srae) {System.out.println("Attribute added: " + srae.getName());}@Overridepublic void attributeRemoved(ServletRequestAttributeEvent srae) {System.out.println("Attribute removed: " + srae.getName());}@Overridepublic void attributeReplaced(ServletRequestAttributeEvent srae) {System.out.println("Attribute replaced: " + srae.getName());}
}

3)HttpSessionListener

用途:监听 HttpSession 的创建和销毁事件。

方法:

  • void sessionCreated(HttpSessionEvent se):在会话创建时被调用。

  • void sessionDestroyed(HttpSessionEvent se):在会话销毁时被调用。

代码:

public class MyHttpSessionListener implements HttpSessionListener {@Overridepublic void sessionCreated(HttpSessionEvent se) {System.out.println("Session created: " + se.getSession().getId());}@Overridepublic void sessionDestroyed(HttpSessionEvent se) {System.out.println("Session destroyed: " + se.getSession().getId());}
}

4)HttpSessionAttributeListener

用途:监听 HttpSession 中属性的添加、修改和删除事件。

方法:

  • void attributeAdded(HttpSessionBindingEvent event):当属性被添加到会话时调用。

  • void attributeRemoved(HttpSessionBindingEvent event):当属性从会话中移除时调用。

  • void attributeReplaced(HttpSessionBindingEvent event):当会话中的属性被替换时调用。

代码:

public class MyHttpSessionAttributeListener implements HttpSessionAttributeListener {@Overridepublic void attributeAdded(HttpSessionBindingEvent event) {System.out.println("Session attribute added: " + event.getName());}@Overridepublic void attributeRemoved(HttpSessionBindingEvent event) {System.out.println("Session attribute removed: " + event.getName());}@Overridepublic void attributeReplaced(HttpSessionBindingEvent event) {System.out.println("Session attribute replaced: " + event.getName());}
}

5)ServletContextListener

用途:监听 ServletContext 的初始化和销毁事件。

方法:

  • void contextInitialized(ServletContextEvent sce):在上下文初始化时被调用。

  • void contextDestroyed(ServletContextEvent sce):在上下文销毁时被调用。

代码:

public class MyServletContextListener implements ServletContextListener {@Overridepublic void contextInitialized(ServletContextEvent sce) {System.out.println("Context initialized");}@Overridepublic void contextDestroyed(ServletContextEvent sce) {System.out.println("Context destroyed");}
}

6)ServletContextAttributeListener

用途:监听 ServletContext 中属性的添加、修改和删除事件。

方法:

  • void attributeAdded(ServletContextAttributeEvent scab):当属性被添加到上下文时调用。

  • void attributeRemoved(ServletContextAttributeEvent scab):当属性从上下文中移除时调用。

  • void attributeReplaced(ServletContextAttributeEvent scab):当上下文中的属性被替换时调用。

代码:

public class MyServletContextAttributeListener implements ServletContextAttributeListener {@Overridepublic void attributeAdded(ServletContextAttributeEvent scab) {System.out.println("Context attribute added: " + scab.getName());}@Overridepublic void attributeRemoved(ServletContextAttributeEvent scab) {System.out.println("Context attribute removed: " + scab.getName());}@Overridepublic void attributeReplaced(ServletContextAttributeEvent scab) {System.out.println("Context attribute replaced: " + scab.getName());}
}

http://www.hkea.cn/news/37472/

相关文章:

  • 联通的网站是谁做的营销的主要目的有哪些
  • 衡阳微信网站地推的方法和技巧
  • 南阳做网站公司哪家好自动发外链工具
  • 潍坊网站制作最低价格网络营销案例有哪些
  • 做网站有谁做谷歌seo视频教程
  • 资深的网站推广完美日记网络营销策划书
  • 90设计网站免费素材网站seo培训
  • 整形美容网站源码上海seo优化bwyseo
  • 武威市住房和建设局网站百度app下载安装普通下载
  • 网站物理结构天津百度推广排名
  • 美容平台网站建设百度指数查询移动版
  • 工程公司手机网站建立网站怎么搞
  • 做网站软件wd惠州seo外包
  • 聊城做网站seo关键词分类
  • 网站做公司女生学网络营销这个专业好吗
  • 网络运营主要工作内容seo教程自学入门教材
  • 用其他商标在自己网站做宣传百度云网盘资源分享网站
  • 对商家而言网站建设的好处淘宝关键词查询工具哪个好
  • 做简单网站代码关键词推广价格
  • 做品牌折扣的网站百度推广的五大优势
  • 南宁比较有好的网站制作公司百度推广后台登录页面
  • 长沙企业网站排名优化windows优化大师和360哪个好
  • 珠海网站开发维护科技公司免费的网络推广渠道有哪些
  • wp建站系统微信营销管理软件
  • 本地打开WordPress慢百度seo优化分析
  • 适合友情链接的网站排名函数
  • 开发公司岗位设置广州seo招聘网
  • 国内web设计网站宣传推广
  • 深圳高端网站定制公司小时seo
  • wordpress主菜单下拉箭头怎么设置台州seo排名优化