只在TOMCAT6.0\conf\server.xml中添加了 <Context path="/test" docBase="D:\WWW\WebROOT" debug="0" reloadable="true" crossContext="true" />是没有用的!!!还要再改一下tomcat6.0默认的初始化参数为false你把web.xml中的初始化参数改为true就OK了 
〈init-param〉 
 〈param-name〉listings〈/param-name〉 
 〈param-value〉false〈/param-value〉 
 〈/init-param〉 
http://ielin.blog.sohu.com/81113940.html

解决方案 »

  1.   

    去看一下你应该就会了:http://www.programfan.com/blog/article.asp?id=34162
      

  2.   

    看一下这个网页上的内容是关于配置的整个过程很不错的:http://www.programfan.com/blog/article.asp?id=34162
      

  3.   

    看一下这个网页关于配置的整个过程:
    http://www.programfan.com/blog/article.asp?id=34162
      

  4.   

    to 3楼:    我的web.xml文件中只有这些:<?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at      http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    --><web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       version="2.5">  <display-name>Welcome to Tomcat</display-name>
      <description>
         Welcome to Tomcat
      </description></web-app>
      

  5.   

    没有以下内容〈init-param〉 
     〈param-name〉listings〈/param-name〉 
     〈param-value〉false〈/param-value〉 
     〈/init-param〉 
      

  6.   

    我把虚拟目录放在了d盘,目录名字叫做test,然后该目录下我见了个WEB-INF目录,之下有以下web.xml文件,文件中存的就是以上内容,然后我在test目录下又写了两个jsp文件,分别取名为1.jsp,2.jsp当我再浏览器中输入http://localhost:8080/test/1.jsp时正常显示页面的内容但是当然输入http://localhost:8080/test/时就抱错404,正确的应该是显示出一个目录,其下有1.jsp和2.jsp文件阿,实在是不知道怎么回事了,哪位高手帮帮忙吧,感激不尽
      

  7.   

    server.xml里面也没有
    〈init-param〉 
     〈param-name〉listings〈/param-name〉 
     〈param-value〉false〈/param-value〉 
     〈/init-param〉只有:<!-- Note:  A "Server" is not itself a "Container", so you may not
         define subcomponents such as "Valves" at this level.
         Documentation at /docs/config/server.html
     -->
    <Server port="8005" shutdown="SHUTDOWN">  <!--APR library loader. Documentation at /docs/apr.html -->
      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
      <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
      <Listener className="org.apache.catalina.core.JasperListener" />
      <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
      <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />  <!-- Global JNDI resources
           Documentation at /docs/jndi-resources-howto.html
      -->
      <GlobalNamingResources>
        <!-- Editable user database that can also be used by
             UserDatabaseRealm to authenticate users
        -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>  <!-- A "Service" is a collection of one or more "Connectors" that share
           a single "Container" Note:  A "Service" is not itself a "Container", 
           so you may not define subcomponents such as "Valves" at this level.
           Documentation at /docs/config/service.html
       -->
      <Service name="Catalina">
      
        <!--The connectors can use a shared executor, you can define one or more named thread pools-->
        <!--
        <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" 
            maxThreads="150" minSpareThreads="4"/>
        -->
        
        
        <!-- A "Connector" represents an endpoint by which requests are received
             and responses are returned. Documentation at :
             Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
             Java AJP  Connector: /docs/config/ajp.html
             APR (HTTP/AJP) Connector: /docs/apr.html
             Define a non-SSL HTTP/1.1 Connector on port 8080
        -->
        <Connector port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" />
        <!-- A "Connector" using the shared thread pool-->
        <!--
        <Connector executor="tomcatThreadPool"
                   port="8080" protocol="HTTP/1.1" 
                   connectionTimeout="20000" 
                   redirectPort="8443" />
        -->           
        <!-- Define a SSL HTTP/1.1 Connector on port 8443
             This connector uses the JSSE configuration, when using APR, the 
             connector should be using the OpenSSL style configuration
             described in the APR documentation -->
        <!--
        <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS" />
        -->    <!-- Define an AJP 1.3 Connector on port 8009 -->
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
        <!-- An Engine represents the entry point (within Catalina) that processes
             every request.  The Engine implementation for Tomcat stand alone
             analyzes the HTTP headers included with the request, and passes them
             on to the appropriate Host (virtual host).
             Documentation at /docs/config/engine.html -->    <!-- You should set jvmRoute to support load-balancing via AJP ie :
        <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">         
        --> 
        <Engine name="Catalina" defaultHost="localhost">      <!--For clustering, please take a look at documentation at:
              /docs/cluster-howto.html  (simple how to)
              /docs/config/cluster.html (reference documentation) -->
          <!--
          <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
          -->              <!-- The request dumper valve dumps useful debugging information about
               the request and response data received and sent by Tomcat.
               Documentation at: /docs/config/valve.html -->
          <!--
          <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
          -->      <!-- This Realm uses the UserDatabase configured in the global JNDI
               resources under the key "UserDatabase".  Any edits
               that are performed against this UserDatabase are immediately
               available for use by the Realm.  -->
          <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 resourceName="UserDatabase"/>      <!-- Define the default virtual host
               Note: XML Schema validation will not work with Xerces 2.2.
           -->
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true"
                xmlValidation="false" xmlNamespaceAware="false">        <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->        <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
                   prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
            -->
             <Context path="/test" docBase="D:\test" debug="0" reloadable="true" crossContext="true" />      </Host>
        </Engine>
      </Service>
    </Server>
      

  8.   

    是Tomcat 6.0\conf\web.xml
    不是Tomcat 6.0\webapps\ROOT\WEB-INFO\web.xml
      

  9.   

    答案:第一:在f盘建立F:\testWeb\WEB-INF文件夹,并把C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF下的web.xml复制到F:\testWeb\WEB-INF中(tomcat6.0的不需要改动)
              第二:在Tomcat 6.0\conf\server.xml中添加如下内容时:在 <Host> 和 </Host> 之间加入
          <Context path="/test" docBase="f:\testWeb"  debug="0" reloadable="true" crossContext="true" />
    在此实验过即使Context中不添加 debug="0" reloadable="true" crossContext="true"也可以,只要如下步骤完成。
              第三:tomcat6.0的也是关闭了目录浏览功能的,这个主要是处于安全性的考虑。要是你的目录下没有默认首页,那你的这个目录下的文件列表就泄露给别人了。
    这个是个配置选项,你可以手动打开,开发时有用,但是生产环境就最好关闭。
    配置选项在TOMCAT/conf/web.xml中找到
    <servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>listings</param-name>
    <param-value>false</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    将其中的
    <init-param>
    <param-name>listings</param-name>
    <param-value>false</param-value>
    </init-param>
    设置改为true
             第四:重启tomcat6.0
             第五:在IE中输入http://localhost/test/
    便会出现如下:
    Directory Listing For /--------------------------------------------------------------------------------
    Filename  Size  Last Modified --------------------------------------------------------------------------------Apache Tomcat/6.0.18至此tomcat6.0虚拟目录设置成功!