2016-05-11 434 views
0

我即將失去理智。Eclipse中的Tomcat - HTTP狀態404請求的資源不可用

我按照這裏的教程

Java servlet tutorial for beginners

我有這個index.html文件

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Insert title here</title> 
</head> 
<body> 
<h1>Hello World</h1> 
</body> 
</html> 

而且web.xml文件

enter image description here

兩個文件在t他WebContent文件夾

我可以毫無問題運行Tomcat和

http://localhost:8080/ 

工作正常,但是當我運行應用程序或去

http://localhost:8080/ServletTutorial/ 

http://localhost:8080/ServletTutorial/index.html 

它給404錯誤請求的資源不可用。

我已經配置Tomcat以使用Tomcat安裝。

我快要崩潰大哭......我已經困在這裏了兩天:(

mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Server version:  Apache Tomcat/8.0.33 
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Server built:   Mar 18 2016 20:31:49 UTC 
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Server number:   8.0.33.0 
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: OS Name:    Windows 10 
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: OS Version:   10.0 
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Architecture:   x86 
mag 11, 2016 11:57:20 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Java Home:    C:\Program Files (x86)\Java\jre1.8.0_91 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: JVM Version:   1.8.0_91-b14 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: JVM Vendor:   Oracle Corporation 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: CATALINA_BASE:   C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: CATALINA_HOME:   C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Command line argument: -Dcatalina.base=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Command line argument: -Dcatalina.home=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Command line argument: -Dwtp.deploy=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\wtpwebapps 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Command line argument: -Djava.endorsed.dirs=C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\endorsed 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.VersionLoggerListener log 
INFORMAZIONI: Command line argument: -Dfile.encoding=Cp1252 
mag 11, 2016 11:57:21 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent 
INFORMAZIONI: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre1.8.0_91\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files (x86)/Java/jre1.8.0_91/bin/client;C:/Program Files (x86)/Java/jre1.8.0_91/bin;C:/Program Files (x86)/Java/jre1.8.0_91/lib/i386;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Antonio\Desktop\eclipse;;. 
mag 11, 2016 11:57:21 AM org.apache.coyote.AbstractProtocol init 
INFORMAZIONI: Initializing ProtocolHandler ["http-nio-8080"] 
mag 11, 2016 11:57:21 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 
INFORMAZIONI: Using a shared selector for servlet write/read 
mag 11, 2016 11:57:21 AM org.apache.coyote.AbstractProtocol init 
INFORMAZIONI: Initializing ProtocolHandler ["ajp-nio-8009"] 
mag 11, 2016 11:57:21 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector 
INFORMAZIONI: Using a shared selector for servlet write/read 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.Catalina load 
INFORMAZIONI: Initialization processed in 1246 ms 
mag 11, 2016 11:57:21 AM org.apache.catalina.core.StandardService startInternal 
INFORMAZIONI: Starting service Catalina 
mag 11, 2016 11:57:21 AM org.apache.catalina.core.StandardEngine startInternal 
INFORMAZIONI: Starting Servlet Engine: Apache Tomcat/8.0.33 
mag 11, 2016 11:57:21 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\docs 
mag 11, 2016 11:57:22 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom 
INFORMAZIONI: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [224] milliseconds. 
mag 11, 2016 11:57:22 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\docs has finished in 730 ms 
mag 11, 2016 11:57:22 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\examples 
mag 11, 2016 11:57:23 AM org.apache.catalina.core.ApplicationContext log 
INFORMAZIONI: ContextListener: contextInitialized() 
mag 11, 2016 11:57:23 AM org.apache.catalina.core.ApplicationContext log 
INFORMAZIONI: SessionListener: contextInitialized() 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\examples has finished in 857 ms 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\host-manager 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\host-manager has finished in 57 ms 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\manager 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\manager has finished in 62 ms 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deploying web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.HostConfig deployDirectory 
INFORMAZIONI: Deployment of web application directory C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT has finished in 31 ms 
mag 11, 2016 11:57:23 AM org.apache.coyote.AbstractProtocol start 
INFORMAZIONI: Starting ProtocolHandler ["http-nio-8080"] 
mag 11, 2016 11:57:23 AM org.apache.coyote.AbstractProtocol start 
INFORMAZIONI: Starting ProtocolHandler ["ajp-nio-8009"] 
mag 11, 2016 11:57:23 AM org.apache.catalina.startup.Catalina start 
INFORMAZIONI: Server startup in 1834 ms 
+0

這兩個文件都在WebContent文件夾中 - 實際上web.xml必須位於WebContent/WEB-INF文件夾中。 – ike3

+0

我想輸入xml文件代碼,但它不允許我0_o – NoobNe0

+0

沒有得到最後的評論。有沒有錯誤? – ike3

回答

1

的應用無法部署到Tomcat,因爲沒有日誌記錄,如

Deployment of web application directory ... ServletTutorial 

當你配置Eclipse來使用Tomcat的安裝嘗試檢查Tomcat的web應用程序文件夾 - 應該有ServletTutorial目錄與應用程式文件檢查根據教程其完整性。如果它不存在,刪除應用程序和補充。它再次執行或使用「清理」菜單選項完全重新發布e服務器窗口。

我建議不要混淆tomcat安裝目錄,但配置它使用工作區元數據文件夾。然後,只有您的應用程序將開始與我的經理,例子和其他不必要的應用程序減少您的發展週期時間。

+0

我已經刪除了服務器並創建了新的,現在它可以工作! 因此,我所遵循的教程是錯誤的,因爲您說web.xml文件必須位於WEB-INF文件夾中,而不是位於帶有index.html的Web內容中,對嗎? 此外,即使應用程序工作,我檢查了Tomcat/webapps,並且沒有Servlet教程目錄。 這是爲什麼? – NoobNe0

+0

這是因爲新服務器配置爲使用.metadata文件夾,而不是webapps目錄。您可以在'.metadata \ .plugins \ org.eclipse.wst.server.core \ tmp0 \ wtpwebapps'附近找到您的應用程序 – ike3

+0

我注意到每次添加一個新的java類時,我都必須刪除並重新創建服務器否則我得到資源未找到錯誤。這是爲什麼?無論如何,這個問題可以避免,而不必刪除和重新創建服務器所有的時間? – NoobNe0

相關問題