Java 监听器
书上的例子packageorg.lxh.listenerdemo;importjavax.servlet.ServletContextEvent;importjavax....
书上的例子
package org.lxh.listenerdemo;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class ServletContextListenerDemo implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
System.out.println("** 容器初始化 -->"
+ event.getServletContext().getContextPath());
}
public void contextDestroyed(ServletContextEvent event) {
System.out.println("** 容器销毁 -->"
+ event.getServletContext().getContextPath());
}
}
配置web.xml
<listener>
<listener-class>
org.lxh.listenerdemo.ServletContextListenerDemo
</listener-class>
</listener>
然后书上说,当容器启动和关闭时,在Tomcat后台将出现以下显示内容:
我的问题是,所谓的容器启动和关闭是什么,我怎么能够在这个例子中看到输出? 展开
package org.lxh.listenerdemo;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class ServletContextListenerDemo implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
System.out.println("** 容器初始化 -->"
+ event.getServletContext().getContextPath());
}
public void contextDestroyed(ServletContextEvent event) {
System.out.println("** 容器销毁 -->"
+ event.getServletContext().getContextPath());
}
}
配置web.xml
<listener>
<listener-class>
org.lxh.listenerdemo.ServletContextListenerDemo
</listener-class>
</listener>
然后书上说,当容器启动和关闭时,在Tomcat后台将出现以下显示内容:
我的问题是,所谓的容器启动和关闭是什么,我怎么能够在这个例子中看到输出? 展开
4个回答
展开全部
我使用的是eclipse,可以在控制台看到
一月 13, 2014 12:42:36 下午 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/user/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
一月 13, 2014 12:42:37 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:forum' did not find a matching property.
一月 13, 2014 12:42:37 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:forumTest' did not find a matching property.
一月 13, 2014 12:42:37 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:tomcate' did not find a matching property.
一月 13, 2014 12:42:37 下午 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
一月 13, 2014 12:42:37 下午 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
一月 13, 2014 12:42:37 下午 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1256 ms
一月 13, 2014 12:42:37 下午 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
一月 13, 2014 12:42:37 下午 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
一月 13, 2014 12:42:38 下午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [214] milliseconds.
** 容器初始化 -->/tomcate
一月 13, 2014 12:42:38 下午 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
一月 13, 2014 12:42:38 下午 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
一月 13, 2014 12:42:38 下午 org.apache.catalina.startup.Catalina start
INFO: Server startup in 968 ms
一月 13, 2014 12:42:57 下午 org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
一月 13, 2014 12:42:57 下午 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
一月 13, 2014 12:42:57 下午 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
一月 13, 2014 12:42:57 下午 org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
** 容器销毁 -->/tomcate
一月 13, 2014 12:42:57 下午 org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
一月 13, 2014 12:42:57 下午 org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
一月 13, 2014 12:42:57 下午 org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
一月 13, 2014 12:42:57 下午 org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
容器就是tomcat,它的启动和关闭你的应用程序需要监听,并作出反应
问一下,级别低得是不是不能用“代码语言”?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询