主要是servlet用的,其基本功能:表明所在目录是一个webapp,并可以做一些相关设置。jsp不用这个文件也可以,不过要在tomcat的server.xml里配置context。有了这个文件就不用配了。

解决方案 »

  1.   

    但是如何在tomcat的server.xml里配置context呢?
      

  2.   

    web-xml是Web应用系统的描叙,用于应用的配置,指定了系统的一些设置,比如welcome 页,servlet控制器等。如果你只运行一个jsp页,它没有什么用,对于一个应用,它是非常必要的。
      

  3.   

    把jsp 文件放Tomcat\webapps\examples\jsp目录下
    如用bean的话把class文件放Tomcat\webapps\examples\WEB-INF\classes目录下再试web.xml可以不用配
      

  4.   

    这个问我解答对了,把分都给我!!
    找到TOMCAT目录下的CONF目录下的server.xml文件      <Host name="localhost" debug="0" appBase="webapps" 
           unpackWARs="true" autoDeploy="true">      <!-- Add the following attributes if you want to turn XML validation
               on. Remember to comment the Host element above. 
               
               Note: XML Schema validation will work with Xerces 2.0.1 or 
               Xerces 2.1. Xerces 2.0.2 and Xerces 2.2 have bugs that prevent 
               their use with Tomcat -->
          <!--
          <Host name="localhost" debug="0" appBase="webapps"
           unpackWARs="true" autoDeploy="true"
           xmlValidation="true" xmlNamespaceAware="true">
          -->        <!-- Uncomment this to cluster this host using JavaGroups. The
                 protocol attribute can be used to configure the JavaGroups
                 network stack (the defaults are used if it's not specified). -->
            <!--
            <Cluster className="org.apache.catalina.cluster.JGCluster"/>
            -->        <!-- Normally, users must authenticate themselves to each web app
                 individually.  Uncomment the following entry if you would like
                 a user to be authenticated the first time they encounter a
                 resource protected by a security constraint, and then have that
                 user identity maintained across *all* web applications contained
                 in this virtual host. -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn"
                       debug="0"/>
            -->        <!-- Access log processes all requests for this virtual host.  By
                 default, log files are created in $CATALINA_HOME/logs.
                 If you wish, you can specify a different
                 directory with the "directory" attribute.  Specify either a relative
                 (to $CATALINA_HOME) or absolute path to the desired directory.
            -->
            <!--
            <Valve className="org.apache.catalina.valves.AccessLogValve"
                     directory="logs"  prefix="localhost_access_log." suffix=".txt"
                     pattern="common" resolveHosts="false"/>
            -->        <!-- Logger shared by all Contexts related to this virtual host.  By
                 default (when using FileLogger), log files are created in the "logs"
                 directory relative to $CATALINA_HOME.  If you wish, you can specify
                 a different directory with the "directory" attribute.  Specify either a
                 relative (to $CATALINA_HOME) or absolute path to the desired
                 directory.-->
            <Logger className="org.apache.catalina.logger.FileLogger"
                     directory="logs"  prefix="localhost_log." suffix=".txt"
            timestamp="true"/>        <!-- Define properties for each web application.  This is only needed
                 if you want to set non-default properties, or have web application
                 document roots in places other than the virtual host's appBase
                 directory.  -->        <!-- Tomcat Root Context -->
            <!--
              <Context path="" docBase="ROOT" debug="0"/>
            -->
    <Context path="/myjsp" #注意虚拟目录名myjsp(http://localhost:8080/myjsp)
                    docBase="e:\jsp" 把你的jsp文件放在哪个盘中
                    crossContext="false"
                    debug="0" 
                    reloadable="true" > 
           </Context>
          </Host>    </Engine>  </Service></Server>
      

  5.   

    http://www.chinajavaworld.net/forum/topic.cgi?forum=43&topic=1188
      

  6.   

    Tomcat新手攻略
    1、下载必要软件
    ①JDK 1.4.2
    ②Tomcat 4.0
    2、配置环境
    windows系统用户:
    我的电脑------〉右键-------〉属性-------〉详细-------〉环境变数
    path = x:\jdk1.4.2\binJAVA_HOME=x:\jdk1.4.2
    CATALINA_HOME=x:\tomcat(这里有的是TOMCAT_HOME=x:\tomcat)
    注:这里x为安装的驱动器。这里要怎么设置取决于bin目录下的startup.bat文件。
    我们可以在编辑状态下打开startup.bat,看究竟这个文件需要读取那个系统变量,我们就设置那个。比如当前我的版本tomcat的startup.bat文件内容如下:
    @echo off
    if "%OS%" == "Windows_NT" setlocal
    rem ---------------------------------------------------------------------------
    rem Start script for the CATALINA Server
    rem
    rem $Id: startup.bat,v 1.4 2002/01/15 02:55:38 patrickl Exp $
    rem ---------------------------------------------------------------------------rem Guess CATALINA_HOME if not defined
    if not "%CATALINA_HOME%" == "" goto gotHome
    set CATALINA_HOME=.
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    set CATALINA_HOME=..
    :gotHome
    if exist "%CATALINA_HOME%\bin\catalina.bat" goto okHome
    echo The CATALINA_HOME environment variable is not defined correctly
    echo This environment variable is needed to run this program
    goto end
    :okHomeset EXECUTABLE=%CATALINA_HOME%\bin\catalina.batrem Check that target executable exists
    if exist "%EXECUTABLE%" goto okExec
    echo Cannot find %EXECUTABLE%
    echo This file is needed to run this program
    goto end
    :okExecrem Get remaining unshifted command line arguments and save them in the
    set CMD_LINE_ARGS=
    :setArgs
    if ""%1""=="""" goto doneSetArgs
    set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
    shift
    goto setArgs
    :doneSetArgscall "%EXECUTABLE%" start %CMD_LINE_ARGS%:end我们可以清楚的看到这个文件需要读取系统变量CATALINA_HOME的值,所以我们在环境变数中把CATALINA_HOME设置为tomcat的安装路径就可以了。3、启动、关闭tomcat
    有2种方法可以启动、关闭安装好的tomcat:
    ① 直接点击运行bin目录下startup.bat和shutdown.bat文件就可以。
    ② 由于前面我们设置了path,所以我们直接在Dos窗口中直接键入startup或shutdown亦可。4、设置虚拟目录
    编辑server文件(x:\tomcat\conf\server.xml)
    因为在tomcat启动时要读取server文件的信息,所以更改server文件后,一定要重新启动tomcat。举个例子:
    我们打算建立一个myJSP的虚拟目录,只要在server.xml文件中加入如下代码即可:
    <Context path="/myJSP" docBase="c:\myJSP" debug="0"
                    reloadable="true" crossContext="true">
    </Context>其中,path为我们要建立的虚拟目录,docBase为实际目录在硬盘上的位置。5、试我们前面工作的成果
    编一个简单的小例子,来测试一下我们的虚拟目录是否可用。
    refresh.jsp (c:\myJSP\refresh.jsp)<%@page language="java"%>
    <%@page import="java.util.Date"%>
    <HTML>
    <HEAD>
    <TITLE>AUTO REFRESH</TITLE>
    <%response.setHeader("refresh","5");%>
    </HEAD>
    <BODY bgcolor=#cc99dd><BR><center><h1>auto refresh example</h1></center><BR>
    <center>refresh time : 5 sencords</center><BR>
    <CENTER>Now Time is: <%=new Date()%></CENTER>
    </BODY>
    </HTML>在地址栏键入http;//localhost:8080/myJSP/refresh.jsp,呵呵,看到效果了吧。注意:myJSP要注意大小写,刚才试了一下写成了“myjsp”就报错!
    推荐个好网站:http://www.chinajavaworld.net/forum/forums.cgi?forum=43
    这是兔八哥的另一个ID!
     
     
      

  7.   

    上面这篇文章是我在Tomcat论坛上找到的,
    感谢: mengdandan(vivan(一直最用心,永远最好听)) ( ) !
    大家可以到那里去看看,感觉不错!