[已解決]tomcat在eclipse中已啟動成功但是訪問時顯示404錯誤?

來源:互聯網
上載者:User

          本文寫給初學者,也寫給自己以後需要重新部署項目時作為參考,如果正好協助了您,請您反饋給我,增加我在成長過程中不斷分享的動力。

 

          網上關於tomcat安裝及環境變數設定的過程已經很多,我再此不再贅述。

 

         問題:tomcat在測試是否安裝成功時可以成功訪問localhost:8080。但是在eclipse中tomcat已經設定好的情況下,部署項目時出現404頁面。

 

        筆者做了以下兩點主要的動作【已解決此問題】:

 

        1、很多教程(書本、視頻)引導大家必須要在web.xml中配置對應的參數,

         我裝的tomcat是8.0.23的

         jdk和jre環境都是1.8.0的

         是不能去手動設定web.xml的

         猜想可能是最新的tomcat與eclipse已經不再需要我們去做這步工作,添加後反而畫蛇添足。

                 我的web.xml檔案代碼如下:

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">  <display-name>FirstWeb</display-name>    <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list></web-app>


         2、以上設定完成,在eclipse中部署後,依然顯示404錯誤。

          度了很久無果,可能是造成404錯誤的原因實在太多吧。

     1)經過多次嘗試偶然發現,在部署前,刪除當前的項目(見下圖)。

     2)並停止tomcat的運行(右鍵--stop)。

     3)僅開啟目前我們編輯的servlet檔案(感覺這裡就是問題的大癥結,因為我上幾次每次都開啟在web.xml檔案裡),點運行就好了。

 

          我的已經部署出來了,趕緊試試這個方法吧。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.