為什么Tomcat的webapps目錄下新建的目錄不能訪問html文件?


在Tomcat安裝目錄中,webapps默認為部署網站用的目錄。webapps/ROOT是網站的根目錄,其它目錄都是網站的子目錄,如webapps\jsp-examples目錄。但是,當我們新建一個子目錄時,卻並不能在瀏覽器里正常訪問。就連HTML文件也訪問不了。為什么會出現這種情況呢?

  原來,在Tomcat中,每一個webapps下的子目錄都被認為是一個JSP站點。因此,該子目錄必需要有JSP站點的必要結構才行。也就是,在創建的子目錄下,必需有WEB_INF目錄以及WEB_INF下的web.xml文件。WEB_INF目錄以及其下的web.xml文件,是JSP用來配置站點用的。

  以test子目錄為例,以下就是正確配置Tomcat子目錄的目錄結構:

        webapps\
            ┝ ROOT\
            │        │
            │        ┕ …
            ┕ test\
                        │
                        ┝ index.html
                        │
                        ┕ WEB_INFO\
                                    │
                                    ┕  web.xml

 

  空的web.xml文件內容如下: 

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  Copyright 2004 The Apache Software Foundation

  Licensed 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/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>

</web-app>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM