在不使用框架的前提下,通过使用xml内联dtd定义实体来实现web.xml拆分。附件给出的web.xml和web-servlets.xml实现了从web.xml中分离出servlet配置,便于工程管理。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app [ <!ENTITY webServlet SYSTEM "web-servlets.xml"> ]> <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_2_5.xsd" id="WebApp_ID" version="2.5"> &webServlet; <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
<servlet> <servlet-name>SimpleServlet</servlet-name> <servlet-class>com.hongyuan.test.SimpleServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>SimpleServlet</servlet-name> <url-pattern>/SimpleServlet</url-pattern> </servlet-mapping>