浏览 3726 次
锁定老帖子 主题:tomcat修改web.xml文件名
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-06-11
import javax.servlet.ServletContext; import org.apache.catalina.Globals; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleListener; import org.apache.catalina.core.StandardContext; /** * 指定tomcat加载web.xml文件位置<br> * 配置如下:修改TOMCAT_HOME/conf/servlet.xml内的context标签,在其之间加入如下语句<br> * <Listener className="SpecifyWebXmlLifecycleListener" webXmlPath="/WEB-INF/zdb.xml"/><br> * <br> * 然后拷贝本类到TOMCAT_TOMCAT/lib/目录下. * @author zhangdb * */ public class SpecifyWebXmlLifecycleListener implements LifecycleListener{ // web.xml文件相对位置 private String webXmlPath; public void lifecycleEvent(LifecycleEvent event) { Lifecycle lifecycle = event.getLifecycle(); if ("before_start".equalsIgnoreCase(event.getType())) { StandardContext context = (StandardContext) lifecycle; ServletContext servletContext = context.getServletContext(); String realWebXmlPath = context.getDocBase() + this.webXmlPath; servletContext.setAttribute(Globals.ALT_DD_ATTR, realWebXmlPath); System.out.println("substitution web.xml file:[" + realWebXmlPath + "]!"); } } public String getWebXmlPath() { return webXmlPath; } public void setWebXmlPath(String webXmlPath) { this.webXmlPath = webXmlPath; } } tomcat的server.xml配置 <Context path="" docBase="E:\workspace\dyit-site\WebRoot"> <Listener className="SpecifyWebXmlLifecycleListener" webXmlPath="/WEB-INF/web_xml/jtt-wan-web.xml"/> </Context> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |