具体做法如下:
1,按模块将servelet从web.xml中拷贝出来,放到一个test.xml中,如test.xml中内容如下:
<servlet>
<servlet-name>testA</servlet-name>
<servlet-class>TestA</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testA</servlet-name>
<url-pattern>/testA.do</url-pattern>
</servlet-mapping>
2,在我的WEB-INF/web.xml中引入test.xml
<!DOCTYPE web-app
[<!ENTITY test SYSTEM "file:///D:/eclipse/workspace/Test/WebRoot/WEB-INF/test.xml">
<!ENTITY admin SYSTEM "admin.xml">]>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
>
&test;
&admin;
以上修改即可,web.xml会在开头引入你的test.xml.然后 &test;表示你放的地方。
如果test.xml和web.xml在同一个文件夹,则 [<!ENTITY test SYSTEM "test.xml">]
如果test.xml在web.xml所在文件夹的ccc文件夹中,则 [<!ENTITY test SYSTEM "ccc/test.xml">]
我的servlet是2.5,2.4应该也管用,其他版本没试过。
这样,我可以在系统开始设计时,将各个模块分开,便于以后系统拆分。
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version: Apache Tomcat/7.0.62
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built: May 7 2015 17:14:55 UTC
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number: 7.0.62.0
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name: Windows 7
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version: 6.1
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture: amd64
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home: D:\javasoft\Java\jdk1.6.0_45\jre
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version: 1.6.0_45-b06
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor: Sun Microsystems Inc.
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE: D:\Tomcat7\apache-tomcat-7.0.62
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME: D:\Tomcat7\apache-tomcat-7.0.62
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:6562
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\Tomcat7\apache-tomcat-7.0.62
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\Tomcat7\apache-tomcat-7.0.62
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\Tomcat7\apache-tomcat-7.0.62/common/endorsed
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.io.tmpdir=D:\Tomcat7\apache-tomcat-7.0.62\temp
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.library.path=D:\javasoft\Java\jdk1.6.0_45\bin;D:\Tomcat7\apache-tomcat-7.0.62\bin
2015-6-5 16:58:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dsun.io.useCanonCaches=false
2015-6-5 16:58:55 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\javasoft\Java\jdk1.6.0_45\bin;D:\Tomcat7\apache-tomcat-7.0.62\bin
2015-6-5 16:58:55 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-80"]
2015-6-5 16:58:55 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
2015-6-5 16:58:55 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 931 ms
2015-6-5 16:58:55 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
2015-6-5 16:58:55 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.62
2015-6-5 16:58:55 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\docs
2015-6-5 16:58:56 org.apache.tomcat.websocket.server.WsSci onStartup
信息: JSR 356 WebSocket (Java WebSocket 1.1) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocket JARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available.
2015-6-5 16:58:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\docs has finished in 724 ms
2015-6-5 16:58:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\examples
2015-6-5 16:58:56 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2015-6-5 16:58:56 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2015-6-5 16:58:56 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@7d0ade7e')
2015-6-5 16:58:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\examples has finished in 700 ms
2015-6-5 16:58:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\host-manager
2015-6-5 16:58:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\host-manager has finished in 115 ms
2015-6-5 16:58:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\manager
2015-6-5 16:58:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\manager has finished in 97 ms
2015-6-5 16:58:57 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\oms
2015-6-5 16:58:57 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:\Tomcat7\apache-tomcat-7.0.62\webapps\oms\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
2015-6-5 16:58:57 org.apache.catalina.loader.WebappClassLoader validateJarFile
信息: validateJarFile(D:\Tomcat7\apache-tomcat-7.0.62\webapps\oms\WEB-INF\lib\servlet-api-2.3.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
2015-6-5 16:58:57 org.apache.catalina.startup.ContextConfig parseWebXml
严重: Parse error in application web.xml file at jndi:/localhost/oms/WEB-INF/web.xml
java.io.FileNotFoundException: Could not resolve XML resource [null] with public ID [null], system ID [rua.xml] and base URI [jndi:/localhost/oms/WEB-INF/web.xml] to a known, local entity.
at org.apache.tomcat.util.descriptor.LocalResolver.resolveEntity(LocalResolver.java:154)
at com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper.resolveEntity(EntityResolver2Wrapper.java:173)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(XMLEntityManager.java:1017)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1235)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1906)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3033)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1555)
at org.apache.catalina.startup.ContextConfig.parseWebXml(ContextConfig.java:1843)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1263)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5416)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1263)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1948)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
2015-6-5 16:58:57 org.apache.catalina.startup.ContextConfig configureStart
严重: Marking this application unavailable due to previous error(s)
2015-6-5 16:58:57 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2015-6-5 16:58:57 org.apache.catalina.core.StandardContext startInternal
严重: One or more components marked the context as not correctly configured
log4j:WARN Continuable parsing error 4 and column 83
log4j:WARN Attribute "debug" with value "FALSE" must have a value from the list "true false null ".
log4j:WARN Continuable parsing error 11 and column 16
log4j:WARN The content of element type "appender" must match "(errorHandler?,param*,layout?,filter*,appender-ref*)".
log4j:WARN Continuable parsing error 21 and column 16
log4j:WARN The content of element type "appender" must match "(errorHandler?,param*,layout?,filter*,appender-ref*)".
log4j:WARN Continuable parsing error 35 and column 16
log4j:WARN The content of element type "appender" must match "(errorHandler?,param*,layout?,filter*,appender-ref*)".
2015-6-5 16:58:58 org.apache.catalina.core.StandardContext startInternal
严重: Context [/oms] startup failed due to previous errors
2015-6-5 16:58:58 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/oms] registered the JDBC driver [oracle.jdbc.driver.OracleDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2015-6-5 16:58:58 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\oms has finished in 1,506 ms
2015-6-5 16:58:58 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\ROOT
2015-6-5 16:58:58 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\Tomcat7\apache-tomcat-7.0.62\webapps\ROOT has finished in 73 ms
2015-6-5 16:58:58 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-80"]
2015-6-5 16:58:58 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
2015-6-5 16:58:58 org.apache.catalina.startup.Catalina start
信息: Server startup in 3280 ms
tomcat 7.0.52开始的版本才会出这个问题,是因为安全的考虑tomcat 7.0.52开始的版本把xmlBlockExterna属性默认为true,要解决这个问题,两种方法:1、把tomcat版本换成7.0.52之前的版本。2、把xmlBlockExterna设成false。
下面是原版解释:
As per discussion with Tomcat developers, xmlBlockExternal=”true” attribute of Tomcat’s Context (context.xml) was set true by default starting from 7.0.52. With xmlBlockExternal=”false”generated/djn-settings.conf can be included】
- 修改conf/context.xml
<Context xmlBlockExternal="false">