zoukankan      html  css  js  c++  java
  • 同一个tomcat中部署多个工程,不能访问的问题

    个人解决最快的方法是:给每个工程的web.xml中加入一个

    <context-param> 
    <param-name>webAppRootKey</param-name> 
    <param-value>web1.root</param-value> 
    </context-param> 

    保证

    <param-value>web1.root</param-value> 不同。

    <param-value>web2.root</param-value> 

    最近有个项目需要在tomcat部署多个项目:(个人解决方案) 
    第一种: 
    在host中加: 
    <Host name="localhost" appBase="webapps" 
           unpackWARs="true" autoDeploy="true" 
           xmlValidation="false" xmlNamespaceAware="false"> 

    <Context path="/xfpm222"  docBase="D: unningXfpm2" debug="0" reloadable="true"> 
    <Resource name="jdbc/Oraclexfpm222" auth="Container" type="javax.sql.DataSource"  maxActive="100"   maxIdle="50"   maxWait="-1" username="xfpm2"   

    password="xfpm2"   driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@162.8.156.40:1521:orcl"/> 
    </Context> 
    </Host> 

    报错1: 
    java.lang.IllegalStateException: Web app root system property already set to dif 
    ferent value: 'webapp.root' = [D: unningXfpm2] instead of [C:Program FilesT 
    omcat 5.5webappsXfpm2] - Choose unique values for the 'webAppRootKey' context 
    -param in your web.xml files! 
            at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(Web 
    Utils.java:132) 
            at org.springframework.web.util.Log4jWebConfigurer.initLogging(Log4jWebC 
    onfigurer.java:118) 
    ...... 

    解决1: 
    是两个项目的设置重复了,导致出错,但我发现web.xml里并没有配置webAppRootKey项,然后查阅网上资料 
    ,原来是因为如果没有web.xm 内没有设置webAppRootKey项,是为默认设置 

    public  static  void  setWebAppRootSystemProperty(ServletContext servletContext) throws  IllegalStateException  { 
            String  param = servletContext.getInitParameter(WEB_APP_ROOT_KEY_PARAM); 
            String  key = (param != null  ? param : DEFAULT_WEB_APP_ROOT_KEY); 
            String  oldValue = System .getProperty(key); 
            if  (oldValue != null ) { 
                throw  new  IllegalStateException ("WARNING: Web app root system property already set: "  + key + " = "  + 
                                                                     

                oldValue + " - Choose unique webAppRootKey values in your web.xml files!" ); 
            } 
            String  root = servletContext.getRealPath("/" ); 
            if  (root == null ) { 
                throw  new  IllegalStateException ("Cannot set web app root system property when WAR file is not  

    expanded"); 
            } 
            System .setProperty(key, root); 
            servletContext.log("Set web app root system property: "  + key + " = "  + root); 
        } 

    从代码看出,该方法其实就是把该web application的根目录的绝对文件路径作为属性保存在 System的属性列表中。该属性的名字,由web.xml文件中的名为"webAppRootKey"的参数值指出。 

    如果不在web.xml中定义 webAppRootKey参数,那么属性名就是缺省的"webapp.root".在我们的petclinic项目中已经定义了 webAppRootKey参数,其值为"petclinic.root",因此,属性的名字 

    就是"petclinic.root". 

    最后将webAppRootKey项配置好,错误解决。 

    以上解释懂一点,但是自己解决方法:在web.xml中加: 
    <context-param> 
    <param-name>webAppRootKey</param-name> 
    <param-value>web1.root</param-value> 
    </context-param> 
    另一个项目中加: 
    <context-param> 
    <param-name>webAppRootKey</param-name> 
    <param-value>web2.root</param-value> 
    </context-param> 


    报错2: 

    Caught exception while loading file struts-default.xml - [unknown location] 
            at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loa 
    dConfigurationFiles(XmlConfigurationProvider.java:795) 
            at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loa 
    dDocuments(XmlConfigurationProvider.java:132) 
    ...... 

    解决2:可能是出现包之间的冲突,可以把冲突的包放在tomcat的common中(xerces-2.6.2.jar) 

    报错3: 
    java.lang.NullPointerException 
            at jimmystudio.util.table.TableParser.getPageCount(Unknown Source) 
            at jimmystudio.util.table.TableParser.getPage(Unknown Source) 
            at jimmystudio.util.table.TableUtils.init(Unknown Source) 
            at org.apache.jsp.util.table.table_jsp._jspService(table_jsp.java:57) 
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) 
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 
            at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper 
    .java:332) 

    解决3:这是同一数据库,出现找不到数据(不知道是页面缓存的问题,还是数据库连接的问题) 
    如果数据用同一数据库可能出现报错!! 
    解决另外建立数据库、用户名和密码,分开连接。 

  • 相关阅读:
    CF1270H
    CF1305G
    LeetCode-Sqrt(x)
    LeetCode-Plus One
    LeetCode-Integer to Roman
    LeetCode-Roman to Integer
    LeetCode-String to Integer (atoi)
    LeetCode-Reverse Integer
    C++
    LeetCode-Gray Code
  • 原文地址:https://www.cnblogs.com/sanhuan/p/4649235.html
Copyright © 2011-2022 走看看