Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 686f42c

Browse files
add listener
1 parent 6890fb3 commit 686f42c

11 files changed

+715
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# javaee-demo
2-
2+
* /TestServlet 测试javaee监听器
33
# 微信扫码使用gitee工具
44
![gitee工具](https://s1.ax1x.com/2018/08/10/P60MMF.jpg)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package cn.netbuffer.listener;
41+
42+
import javax.servlet.ServletContextAttributeEvent;
43+
import javax.servlet.ServletContextAttributeListener;
44+
import javax.servlet.annotation.WebListener;
45+
46+
/**
47+
* Web application lifecycle listener.
48+
*
49+
* @author Arun Gupta
50+
*/
51+
@WebListener
52+
public class MyContextAttributeListener implements ServletContextAttributeListener {
53+
54+
@Override
55+
public void attributeAdded(ServletContextAttributeEvent event) {
56+
System.out.println("MyContextAttributeListener.attributeAdded: " + event.getName());
57+
}
58+
59+
@Override
60+
public void attributeRemoved(ServletContextAttributeEvent event) {
61+
System.out.println("MyContextAttributeListener.attributeRemoved: " + event.getName());
62+
}
63+
64+
@Override
65+
public void attributeReplaced(ServletContextAttributeEvent event) {
66+
System.out.println("MyContextAttributeListener.attributeReplaced: " + event.getName());
67+
}
68+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package cn.netbuffer.listener;
41+
42+
import javax.servlet.ServletContextEvent;
43+
import javax.servlet.ServletContextListener;
44+
import javax.servlet.annotation.WebListener;
45+
46+
/**
47+
* Web application lifecycle listener.
48+
*
49+
* @author Arun Gupta
50+
*/
51+
@WebListener
52+
public class MyContextListener implements ServletContextListener {
53+
54+
@Override
55+
public void contextInitialized(ServletContextEvent sce) {
56+
System.out.println("MyContextListener.contextInitialized: " + sce.getServletContext().getContextPath());
57+
}
58+
59+
@Override
60+
public void contextDestroyed(ServletContextEvent sce) {
61+
System.out.println("MyContextListener.contextDestroyed: " + sce.getServletContext().getContextPath());
62+
}
63+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package cn.netbuffer.listener;
41+
42+
import javax.servlet.http.HttpSessionActivationListener;
43+
import javax.servlet.http.HttpSessionEvent;
44+
45+
/**
46+
* Web application lifecycle listener.
47+
*
48+
* @author Arun Gupta
49+
*/
50+
public class MyHttpSessionActivationListener implements HttpSessionActivationListener {
51+
52+
@Override
53+
public void sessionWillPassivate(HttpSessionEvent se) {
54+
System.out.println("MyHttpSessionActivationListener.sessionWillPassivate: " + se.getSession().getId());
55+
}
56+
57+
@Override
58+
public void sessionDidActivate(HttpSessionEvent se) {
59+
System.out.println("MyHttpSessionActivationListener.sessionDidActivate: " + se.getSession().getId());
60+
}
61+
62+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package cn.netbuffer.listener;
41+
42+
import javax.servlet.annotation.WebListener;
43+
import javax.servlet.http.HttpSessionAttributeListener;
44+
import javax.servlet.http.HttpSessionBindingEvent;
45+
46+
/**
47+
* Web application lifecycle listener.
48+
*
49+
* @author Arun Gupta
50+
*/
51+
@WebListener
52+
public class MyHttpSessionAttributeListener implements HttpSessionAttributeListener {
53+
54+
@Override
55+
public void attributeAdded(HttpSessionBindingEvent event) {
56+
System.out.println("MyHttpSessionAttributeListener.attributeAdded: " + event.getName());
57+
}
58+
59+
@Override
60+
public void attributeRemoved(HttpSessionBindingEvent event) {
61+
System.out.println("MyHttpSessionAttributeListener.attributeRemoved: " + event.getName());
62+
}
63+
64+
@Override
65+
public void attributeReplaced(HttpSessionBindingEvent event) {
66+
System.out.println("MyHttpSessionAttributeListener.attributeReplaced: " + event.getName());
67+
}
68+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package cn.netbuffer.listener;
41+
42+
import javax.servlet.http.HttpSessionBindingEvent;
43+
import javax.servlet.http.HttpSessionBindingListener;
44+
45+
/**
46+
* Web application lifecycle listener.
47+
*
48+
* @author Arun Gupta
49+
*/
50+
public class MyHttpSessionBindingListener implements HttpSessionBindingListener {
51+
52+
@Override
53+
public void valueBound(HttpSessionBindingEvent event) {
54+
System.out.println("MyHttpSessionBindingListener.valueBound: " + event.getName());
55+
}
56+
57+
@Override
58+
public void valueUnbound(HttpSessionBindingEvent event) {
59+
System.out.println("MyHttpSessionBindingListener.valueUnbound: " + event.getName());
60+
}
61+
62+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /