javaWeb之监听器简介
2016-10-06 16:57
302 查看
javaWeb之监听器简介
代码:
index.jsp:
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> This is my JSP page. <br> </body> </html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>FirstListener</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <listener> <listener-class>com.mooc.listener.FirstListener</listener-class> </listener> </web-app>
FirstListener.java:
package com.mooc.listener; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class FirstListener implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub System.out.println("contextDestroyed"); } @Override public void contextInitialized(ServletContextEvent arg0) { // TODO Auto-generated method stub System.out.println("contextInitialized"); } }
监听器的启动顺序:
相关文章推荐
- Resin服务器的使用 -Java Web服务器选择简介 [转帖]
- JavaWebStudio系列开发工具Visaul Struts版本简介
- JavaWeb 监听器
- 【JavaWeb】commons-codec包简介
- Java中web服务的简介
- JavaWebStudio系列开发工具Visaul Struts版本简介
- javaWeb_10-request简介
- Java Web框架简介
- JavaWeb_day5-监听器和过滤器
- java-WEB中的监听器Lisener
- 用Java缓存机制创建更快的Web应用----简介和配置
- Java EE WEB工程师培训-JDBC+Servlet+JSP整合开发之01.JDBC简介 推荐
- Java EE WEB工程师培训—JDBC+Servlet+JSP整合开发之32. HTML简介 推荐
- JavaWEB开发-Servlet事件监听器
- Java监听器简介
- Struts与Java-Web应用简介
- 传智播客java web 学习,Servlet事件监听器
- 常用的Java Web框架简介
- JavaEE Web开发之Filter和Listener(过滤器和监听器)
- javaWeb_09-ServletContext简介和方法介绍