不一定在webapps下面,只要在server.xml 中配置一下就行了!
我估计和4.0一样的
<Context path="/math" docBase="C:\eclipse\workspace\math site\math" debug="0" reloadable="true" crossContext="true"> 
</Context>      

解决方案 »

  1.   

    正如楼上所说,补充的是:
    1 楼上设的是虚拟目录
    2 server.xml在tomcat的安装目录的conf目录下
      

  2.   

    5.0及以后版本也可以单独写一个以.xml为后缀的文件,在其中加入
    <Context path="/math" docBase="C:\eclipse\workspace\math site\math" debug="0" reloadable="true" crossContext="true"> 
    </Context>      
    然后保存在catalina_home\conf\localhost下就可以了!
      

  3.   

    在tomcat启动的时候怎么设置才能让它自动的进行一些初始化,比如初始化数据库等等
      

  4.   

    初始化数据库啊,你是否想用连接池,如果这样,你可以在catalina_home\conf\localhost下写个.xml文件(5.0以后),或者在server.xml中加入:
     <Resource name="jdbc/TestDB"
                   auth="Container"
                   type="javax.sql.DataSource"/>  <ResourceParams name="jdbc/TestDB">
        <parameter>
          <name>factory</name>
          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
        </parameter>    <!-- Maximum number of dB connections in pool. Make sure you
             configure your mysqld max_connections large enough to handle
             all of your db connections. Set to 0 for no limit.
             -->
        <parameter>
          <name>maxActive</name>
          <value>100</value>
        </parameter>    <!-- Maximum number of idle dB connections to retain in pool.
             Set to 0 for no limit.
             -->
        <parameter>
          <name>maxIdle</name>
          <value>30</value>
        </parameter>    <!-- Maximum time to wait for a dB connection to become available
             in ms, in this example 10 seconds. An Exception is thrown if
             this timeout is exceeded.  Set to -1 to wait indefinitely.
             -->
        <parameter>
          <name>maxWait</name>
          <value>10000</value>
        </parameter>    <!-- MySQL dB username and password for dB connections  -->
        <parameter>
         <name>username</name>
         <value>zhutouzip</value>
        </parameter>
        <parameter>
         <name>password</name>
         <value>12388321</value>
        </parameter>    <!-- Class name for the old mm.mysql JDBC driver - uncomment this entry and comment next
             if you want to use this driver - we recommend using Connector/J though
        <parameter>
           <name>driverClassName</name>
           <value>org.gjt.mm.mysql.Driver</value>
        </parameter>
         -->
        
        <!-- Class name for the official MySQL Connector/J driver -->
        <parameter>
           <name>driverClassName</name>
           <value>com.mysql.jdbc.Driver</value>
        </parameter>
        
        <!-- The JDBC connection url for connecting to your MySQL dB.
             The autoReconnect=true argument to the url makes sure that the
             mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
             connection.  mysqld by default closes idle connections after 8 hours.
             -->
        <parameter>
          <name>url</name>
          <value>jdbc:mysql://localhost:3306/mywebdata?autoReconnect=true</value>
        </parameter>
      </ResourceParams>
    然后在你的项目下WEB-INF\下的web.xml中对应加入:
    <resource-ref>
          <description>DB Connection</description>
          <res-ref-name>jdbc/TestDB</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
      </resource-ref>
    这样在初始启动时就将数据库帮定到tomcat的容器环境当中了!
      

  5.   

    楼上那样配置不好,最好是在web.xml中进行配置,把代码copy到哪都能运行,有谁知道web.xml中参数的意思?
      

  6.   

    你如果配置连接池的话,既要在server.xml中配置,也要在web.xml中配置,这些你仔细配置过几次就知道个元素的意思了!看看tomcat-docs
      

  7.   

    我的连接池是写在代码里的,不需要配置的。
    现在的问题是启动的时候要直接加载一个servlet
      

  8.   

    to up  this is right
      

  9.   

    web.xml配置servlet <servlet>
    <servlet-name>AServlet</servlet-name>
    <servlet-class>org.chen.AServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
          <servlet-mapping>
             <servlet-name>AServlet</servlet-name>
             <url-pattern>/servlet/*</url-pattern>
          </servlet-mapping>
      

  10.   

    嗯,注意楼上的
    <load-on-startup>1</load-on-startup>
      

  11.   

    如果你的Servlet仅仅只为初始化环境的化,
    <servlet-mapping />不需要.
      

  12.   

    5.0及以后版本也可以单独写一个以.xml为后缀的文件,在其中加入
    <Context path="/math" 
        docBase="C:\eclipse\workspace\math site\math" debug="0" reloadable="true"       
        crossContext="true"> 
    </Context>      
    然后保存在catalina_home\conf\localhost下就可以了
      

  13.   

    为什么我的catalina_home\conf\下有个Catalina,在其下面才有localhost,怎么回事?