监听tomcat服务器启动/关闭很简单(2步):

1. 建立一个类实现ServletContextListener接口,重写其中的方法(contextDestroyed和contextInitialized)。

package action;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class SystemListener implements ServletContextListener{
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
}

2. 在web.xml中注册该监听器。如下:

<listener>
<description>监听tomcat</description>
<display-name>test</display-name>
<listener-class>listener.SystemListener</listener-class>
</listener>

监听tomcat启动和关闭就这么简单地完成了。可以把一些tomcat启动时就需要初始化的属性和需要完成的操作放到这步来完成。

下面是完整的项目代码:

1. 目录结构

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAT4AAAHOCAIAAACOyPJ+AAAgAElEQVR4nO2de3AU153v+5/U/rmu2q3K5o8tZ52EtU1tHBOjiAnhujZ7A7n7h/emiiyq9doCnF5jkvBIHONFXB4GMbzCrBEYG1sIG2QBQhYojGFtlUy8vFIsDxssrFkDQgJJoxl59JyeGcl9/+iZ7tPdpx8z0zPTp+f7qVN2d8959LT6wznd0+fXnFgYrlz9uO4PO5a1tdX9YceVqx8XqBUAyhauEJVeufrxsra20KUGoe/CsrY238lPYS8AzuKMuteOvSwnURSbPrgpjt3u/GT32S9qT15/o2r3kX9e1eRIQwAACQfUvdr8snp11bK2tubPP3vno7cOBn9a/9Y/LF2zv+rXUBcAJ8ld3d3rt+xev2X3en9yoD45UD9xe0/k2raeM2s+P7FiWVvb35/prjp0cs2//fjFXy//2a/fW7F6h66CUMDH8cGs2syhCADexELdjo4Ov99P/WjL6h2b/uOCOPxHfbpy9eOn6y/+eOf1RSuaf77onZ8veoV2rQt1AcgdM3Xb29unT58+bdo0owwrV+wSB9soSRSvXP14x5p3Fz/3Rs3KAPUeFc9l8AVCoiiKQV6zQTI1DR8kMig5AChXDNWVvF2wYIGJuov/7XXx3kF6sobsQoO8Wlg+SO1i0esC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gSpUWySYy8rLgV5jjIrX2t/iNI5I4oVKAqMqZtXbCqdd5mtvkBIN0KWV9U9MdEZ64NU6VtBFCtQKBhTN6/YVDmrS7/otVRXWUcUK+A4jKmbV2wqc3VV41cy6pxmIK1c4voCIWW4jShWoLgwpm5esaks1FXfjQpornBVN5aIK+GMgIhiBYoLY+qWLDaVfRDFChQFxtQtVWwq+yCKFSgOjKlbgthU9kEUK1BEGFMXsakAkGBMXQCABNQFgEmgLgBMAnUBYBKoCwCTeERdxKYC5QZj6uYVm8pVIA4OyA/21M09NpWrgLogPxhTt3ixqQBwN4ypW7zYVAC4G8bUzSs2lX72HvlMser5Ym0wKntb9LMDKVtEXXMIYQVygDF1HYpNRduiDkyjvgylbtEFrDKv32hnEMIK5ARj6uYVm0ofkoaqrj6iDXULJWCVPuSNQRAcUfsvBUJYgWxhTN28YlOlIYJF5aOu6aRcvYpagRHCCuQHY+rmGZtKGyyK+IWGiBRFjlCDgUx3arwlE7CKVr9hiwhhBfKDMXXzik1FCRal3CLy8bxPv9XWFtrdLfJCVXsHCiGsgAMwpi4DsalsghBWID8YU9f9salsghBWIE8YU9fVsalsghBWwAkYUxexqQCQYExdAIAE1AWASaAuAEwCdQFgkkKpi4gzABSUgqjLZMQZAJji/wM4JWSPjr4D6gAAAABJRU5ErkJggg==" alt="" width="239" height="354" />

2. 监听类

package listener;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import pub.SystemProperty; /**
* 系统上下文启动/关闭监听
* 把需要初始化的数据放在contextInitialized方法里
*
* @author Sky
* @date 2016年8月10日 上午9:32:09 listener
*/
public class SystemListener implements ServletContextListener { @Override
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("tomcat关闭了...");
} @Override
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("tomcat启动了..."); /**
* 读取系统运行基本参数
* 读取静态参数
*/
InputStream input = null;
try {
input = SystemListener.class.getClassLoader().getResourceAsStream(
"sqlProperty.properties");
Properties p = new Properties();
p.load(input); String sqlPort = p.getProperty("port", "3306");
SystemProperty.port = (sqlPort == null || "".equals(sqlPort)) ? 3306
: Integer.parseInt(sqlPort);
SystemProperty.password = p.getProperty("password"); System.out.println("系统初始化成功"); } catch (Throwable e) {
e.printStackTrace();
System.out.println("系统配置文件SystemProperty.properties不存在或读取错误");
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} /**
* 读取时间配置
* 读取其他配置文件,并把配置文件的数据加入静态容器中,以便通过类名取出使用
*/
input = null;
try {
input = SystemListener.class.getClassLoader().getResourceAsStream(
"timeProperty.properties");
Properties p = new Properties();
p.load(input);
//列举
Enumeration<?> propNames = p.propertyNames();
while (propNames.hasMoreElements()) {
String key = (String) propNames.nextElement();
String value = p.getProperty(key, "");
SystemProperty.propList.put(key, value); //放入静态容器中
} System.out.println("时间配置初始化成功"); } catch (Throwable e) {
e.printStackTrace();
System.out.println("时间配置文件timeProperty.properties不存在或读取错误");
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

3. struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="abc" namespace="/" extends="struts-default">
<action name="test" class="action.TestAction">
<result name="input">/index.jsp</result>
<result name="success">/success.jsp</result>
<result name="fail">/fail.jsp</result>
</action>
</package>
</struts>

3. 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" version="3.0"> <listener>
<description>监听tomcat</description>
<display-name>test</display-name>
<listener-class>listener.SystemListener</listener-class>
</listener> <filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
</web-app>

4. 静态属性、容器类(方便使用类名直接调用)

package pub;

import java.util.HashMap;
import java.util.Map; /**
* 静态存储系统运行所需的基本参数,在启动的时候被初始化
*
* @author Sky
* @date 2016年8月10日 上午10:19:12
* pub
*/
public class SystemProperty {
/*
* 设置为静态,直接使用类名调用
*/
public static int port; //端口号
public static String password; //密码
//静态容器,用来存储后面扩展添加的配置(添加其他的配置文件,使得本类来调用)
public static Map<String, String> propList = new HashMap<String, String>();
}

5. properties配置文件

sqlProperty.properties

#端口号
port=1234
#密码
password=6666

timeProperty.properties

#默认时间2秒
normalTime=2000
#一天
oneDay=86400000

6. 测试(使用)类

package action;

import pub.SystemProperty;
import com.opensymphony.xwork2.ActionSupport; public class TestAction extends ActionSupport {
private static final long serialVersionUID = 1L; @Override
public String execute() throws Exception { // 因为是静态变量,所以直接从类名.变量的方式获取
int port = SystemProperty.port;
String password = SystemProperty.password; System.out.println("port=" + port);
System.out.println("password=" + password); //从静态容器中取
String normalTime = SystemProperty.propList.get("normalTime");
String oneDay = SystemProperty.propList.get("oneDay"); System.out.println("normalTime=" + normalTime);
System.out.println("oneDay=" + oneDay); return SUCCESS;
}
}

7. 输出结果如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPkAAABnCAIAAABNQXP0AAAIQElEQVR4nO2dzbXjNgxGVZcKUj3epYJUkBN3kcWsvc+ZLt4sbMv8+QBCEiyTxndXeRqYpKUripRJZPr1++fX759///v/r7//+RGYpgn+t3SEEAeuyzRN8+XmVd5kcZ2QD0DXSRToOiH7oOskCnSdRIGukyjQdRIFuk6iQNdJFLpz/XaZp2larn5lye9or8uUAOvMQ/R2Patzaj1x5ktdzxUFrq9eTkpgIbruexJM17vkG11frVuu99JQv367zOnxp/tZxdcl//sRh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+DMM+PUPeCGu/LpSmpRbYq3ox7VyrrR9p6Aa4H6u/ljYJL8pPQ3uLGY/+XS8mRFJJSv2gM7L3x3jXaJZbQpsHi29Ssy8vjYVBCoVuYsbjwBgm18/gun6SsOuFW7J/+J032HmdFqu6jt865KdEuEFfd5fNdaGu/GhvMcOxfW4qvHlt5BoonAVID/sJ9LWgOULnulyR6ibAdLo+KM655a8K7w/xfXY9v+8mZjSa7xyFHrB6MdPMqyEUJM72YVWbfl09+lOUrS4cpSihPQsaxfQWMxam35L0N2pG10FB2dkDzuAzmxcijVKSIg89dMsmw8LqJikoE7ysHMGr3mLGoZ81Am9g7KkUceZ7XW/PEEgsvs51bckNCc0Xu07PScbXuU6IAF0nUaDrJAp0nUThD7lQn48rCoKfAAAAAElFTkSuQmCC" alt="" />

如有问题,请联系QQ:409169399,答案:Sky。

监听tomcat服务器启动/关闭并从配置文件中读取参数进行初始化的更多相关文章

  1. 监听Web容器启动与关闭

    在Servlet API 中有一个 ServletContextListener 接口,它能够监听 ServletContext 对象的生命周期,实际上就是监听 Web 应用的生命周期. 要监听web ...

  2. Tomcat服务器启动常见问题

    参考:http://www.cnblogs.com/xdp-gacl/p/3729033.html 学习web开发,需要先安装一台web服务器,然后再在web服务器中开发相应的web资源,供用户使用浏 ...

  3. 监听程序未启动或数据库服务未注册到该监听程序。启动该监听程序并注册数据库服务 然后重新运行 em configuration assistant。

    在WIN 7/64Bit上安装ORACLE 11gR2后,管理网页Database Control(如:https://localhost:1158/em)始终登录不进去,总是说密码错误,使用配置工具 ...

  4. Oracle数据库监听服务无法启动

    (1) 安装好Oracle后,启动Net Manager,测试orcl失败,报错“ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务”,需要修改监听文件.修改前: # list ...

  5. Android中如何监听GPS开启和关闭

    转自 chenming 原文 Android中如何监听GPS开启和关闭   摘要: 本文简单总结了如何监听GPS开关的小技巧 有时需要监听GPS的开关(这种需求并不多见).实现的思路是监听代表 GPS ...

  6. oracle监听程序无法启动(TNS-12560: TNS: 协议适配器错误,TNS-00530: 协议适配器错误)

    问题描述1:   C:\Users\Administrator>lsnrctl start LSNRCTL for 64-bit Windows: Version 11.2.0.1.0 - Pr ...

  7. oracle 11g在安装过程中出现监听程序未启动或数据库服务未注册到该监听程序

    15511477451 原文 oracle 11g在安装过程中出现监听程序未启动或数据库服务未注册到该监听程序? 环境:win7 64位系统.oracle11g数据库 问题描述:在win7 64位系统 ...

  8. JAVAWEB tomcat服务器启动错误原因总结

    tomcat服务器启动错误: org.apache.catalina.LifecycleException    这种异常的原因是  servlet的代码出现了错误 实例: 这里的servlet由于使 ...

  9. oracle监听查看、启动和停止

    oracle监听查看.启动和停止 查看监听lsnrctl status 停止监听lsnrctl stop 启动监听lsnrctl start

随机推荐

  1. ecilipse Javadoc文档注释

    — 标签 @param @param 空格后面跟上形参(不是数据类型)空格后跟着对该参数的描述. 在描述中第一个名字为该变量的数据类型 对于参数的描述是一个句子,最好不要首字母大写, 如果出现了句号这 ...

  2. 直接引用windows命名空间

    再逛博客的时候,看见一段这样代码.获取系统密码的 static void DumpCredentials(Windows.Security.Credentials.PasswordCredential ...

  3. GCC警告提示错误“cc1:all warnings being treated as errors”

    http://blog.csdn.net/zhangjs0322/article/details/25131787

  4. poj 1195Mobile phones

    http://poj.org/problem?id=1195 #include <cstdio> #include <cstring> #include <algorit ...

  5. 破解简单Mifare射频卡密钥杂记

    先要了解一点大学城浴卡用的是什么卡,经查证是Mifare S50卡,也有叫ISO14443A的(协议名).本来想看看大学城浴卡有没有安全漏洞,没想到浴卡公司在安全性上几乎是蔑视我们大学生的智商,虽然被 ...

  6. 【HDOJ】1107 武林

    简单模拟,题目数据太弱太弱了. /* 1107 */ #include <iostream> #include <cstdio> #include <cstring> ...

  7. BZOJ1627: [Usaco2007 Dec]穿越泥地

    1627: [Usaco2007 Dec]穿越泥地 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 478  Solved: 303[Submit][Sta ...

  8. Spark处理Json格式数据(Python)

    前言   Spark能够自动推断出Json数据集的“数据模式”(Schema),并将它加载为一个SchemaRDD实例.这种“自动”的行为是通过下述两种方法实现的:   jsonFile:从一个文件目 ...

  9. HDU_1430——魔板,预处理,康托展开,置换,string类的+操作

    Problem Description 在魔方风靡全球之后不久,Rubik先生发明了它的简化版——魔板.魔板由8个同样大小的方块组成,每个方块颜色均不相同,可用数字1-8分别表示.任一时刻魔板的状态可 ...

  10. 使用libevent进行多线程socket编程demo

    最近要对一个用libevent写的C/C++项目进行修改,要改成多线程的,故做了一些学习和研究. libevent是一个用C语言写的开源的一个库.它对socket编程里的epoll/select等功能 ...