记录:tomcat,404错误,虚拟目录,listings设置,Tomcat Native library报错

在系统重装后,配置好Tomcat和JDK,将项目部署到webapps下,遇到404错误。通过在项目中添加index.html并修改web.xml的welcome-file-list解决404问题。当希望展示项目目录时,发现需要Tomcat Native library的1.1.8版本,下载后解决了报错。进一步设置servlet的listings为true,使得项目能够列出目录内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

===========================学习tomcat的点滴记录=============================================================================

系统重装后,配置好jdk和tomcat环境变量,把项目test1复制到重装的tomcat的webapps下,tomcat能够运行。

进http://localhost:8080/manager/html,打开test1,出来404报错页面。


针对本机出现的问题最后解决方法:test1项目里面没有index.html这样的默认页面。加入index.html后,可以正常打开。

我要求的是没有index.html,可以在http://localhost:8080里面点test1,出来test1里面的目录。

如是在conf文件里的web.xml进行修改:

<init-param>
            <param-name>listings</param-name>
            <param-value>true</param-value>
        </init-param>

listings的值默认为false,设置为true,就行显示目录。

============================过程记录=======================================

查看logs,发现提示为:Tomcat Native library是1.1.1,要求1.1.8,于是网上下了tcnative-1.dll的1.1.8版本,放到bin目录下面。

tomcat运行没有错误了。


可还是报404错误。http://localhost:8080/能够打开,发现除了本身root项目能运行,只有docs这个项目能够打开。

而这两个项目有个共同点就是都有index.html。于是给test1加入默认页index.html(默认主页可以在conf/web.xml里面修改welcome-file-list),test1可以运行。


因为我的test1项目里面是测试用,有多个测试例子,所以不希望每次从主页跳,之前是直接能目录显示test1里面的文件。


看conf文件夹的web.xml的welcome-file-list上面的注释发现:

 <!-- ==================== Default Welcome File List ===================== -->
  <!-- When a request URI refers to a directory, the default servlet looks  -->
  <!-- for a "welcome file" within that directory and, if present,          -->
  <!-- to the corresponding resource URI for display.  If no welcome file   -->
  <!-- is present, the default servlet either serves a directory listing,   -->
  <!-- or returns a 404 status, depending on how it is configured.          -->
  <!--                                                                      -->
  <!-- If you define welcome files in your own application's web.xml        -->
  <!-- deployment descriptor, that list *replaces* the list configured      -->
  <!-- here, so be sure that you include any of the default values that     -->
  <!-- you wish to include.    -->

大意是默认找welcom file,如果找不到,就返回目录或404错误,返回什么取决于设置。

在网上查了下设置目录为listings这个参数,于是找到web.xml里面的servlet下,修改listings的值为true(默认为false)。结果成功。


小插曲:修改完之后,还是404,后在找半天,才发现true写成了ture。如此大意真是不应该。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值