Author: jfrederic.clere(a)jboss.com
Date: 2010-01-26 09:38:17 -0500 (Tue, 26 Jan 2010)
New Revision: 1372
Added:
sandbox/webapps/src/MyServletContextListener.java
Modified:
sandbox/webapps/build.xml
Log:
Add an example of dynamic add of a servlet.
Modified: sandbox/webapps/build.xml
===================================================================
--- sandbox/webapps/build.xml 2010-01-26 14:37:25 UTC (rev 1371)
+++ sandbox/webapps/build.xml 2010-01-26 14:38:17 UTC (rev 1372)
@@ -5,11 +5,11 @@
<!--
<javac srcdir="src"
classpath="/home/jfclere/tc6.0.x/output/build/lib/servlet-api.jar"
destdir="classes" />
-->
- <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/apache-tomcat-5.5.17/common/lib/servlet-api.jar"
destdir="classes" excludes="Comet*" />
+ <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/apache-tomcat-5.5.17/common/lib/servlet-api.jar"
destdir="classes" excludes="Comet*,MyServletContextListener*" />
- <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/jbossweb_trunk/output/jars/jbossweb.jar:/home/jfclere/jbossweb_trunk/output/jars/servlet-api.jar"
destdir="classes" includes="Comet*" />
+ <javac srcdir="src" debug="on"
debuglevel="lines,vars,source"
classpath="/home/jfclere/jbossweb_trunk/output/jars/jbossweb.jar:/home/jfclere/jbossweb_trunk/output/jars/servlet-api.jar"
destdir="classes" includes="Comet*,MyServletContextListener*" />
- <jar destfile="./lib/myservlets.jar" basedir="./classes"
excludes="Comet*" />
+ <jar destfile="./lib/myservlets.jar" basedir="./classes"
excludes="Comet*,MyServletContextListener*" />
<war destfile="myapp.war" webxml="myapp.xml">
<fileset dir="html" />
@@ -61,5 +61,8 @@
<war destfile="comet.war" needxmlfile="false" >
<classes dir="./classes" includes="Comet*" />
</war>
+ <war destfile="all.war" needxmlfile="false" >
+ <classes dir="./classes"/>
+ </war>
</target>
</project>
Added: sandbox/webapps/src/MyServletContextListener.java
===================================================================
--- sandbox/webapps/src/MyServletContextListener.java (rev 0)
+++ sandbox/webapps/src/MyServletContextListener.java 2010-01-26 14:38:17 UTC (rev 1372)
@@ -0,0 +1,56 @@
+/*
+ * Copyright(c) 2010 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ * @author Jean-Frederic Clere
+ * @version $Revision: 420067 $, $Date: 2006-07-08 09:16:58 +0200 (sub, 08 srp 2006) $
+ */
+
+import java.io.*;
+import java.text.*;
+import java.util.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import javax.servlet.annotation.WebListener;
+
+/**
+ * ServletContextListener that adds a Servlet.
+ * 3.0 example.
+ */
+
+@WebListener
+public class MyServletContextListener implements ServletContextListener {
+ public void contextInitialized(ServletContextEvent event) {
+ System.out.println("contextInitialized");
+ try {
+ ServletContext sc = event.getServletContext();
+ Class<MyCount> servletCl = (Class<MyCount>)
Class.forName("MyCount");
+ MyCount servlet = sc.createServlet(servletCl);
+ ServletRegistration.Dynamic sr = (ServletRegistration.Dynamic)
sc.addServlet("test.MyCount", servlet);
+ sr.addMapping("/newMyCount");
+ } catch (Exception e) {
+ System.out.println("contextInitialized failed: " + e);
+ }
+ }
+ public void contextDestroyed(ServletContextEvent event) {
+ System.out.println("contextDestroyed");
+ }
+}
Show replies by date