為什麼Tomcat的webapps目錄下建立的目錄不能訪問html檔案?

來源:互聯網
上載者:User

標籤:

 

 在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>

 

  

為什麼Tomcat的webapps目錄下建立的目錄不能訪問html檔案?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.