在SO上有這樣的問題,但沒有一個解決了我的問題,我想不出任何可能導致此錯誤的問題。Tomcat servlet - 狀態404請求的資源不可用
我試圖寫一個簡單的servlet,只輸出「Hello World」:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class PrintServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World");
}
}
我所做的就是編譯java文件,編譯後的文件移動到/usr/local/apache-tomcat-7.0.65/webapps/examples/WEB-INF/classes
,再加入這些到網上位於/usr/local/apache-tomcat-7.0.65/webapps/examples/WEB-INF
.xml文件:
<servlet>
<serlet-name>PrintServlet</servlet-name>
<servlet-class>PrintServlet</servlet-name>
</servlet>
<servlet-mappinng>
<servlet-name>PrintServlet</servlet-name>
<url-pattern>/servlet/PrintServlet</url-pattern>
</servlet-mapping>
並試圖訪問使用http://localhost:8080/servlet/PrintServlet
該servlet。
我收到錯誤消息:狀態404請求的資源不可用。
我沒有看到可能出現錯誤的地方,我只是簡單地跟隨教程。有人可以幫我嗎?
編輯:在catalina.out的
日誌文件(通過調用尾-f catalina.out的得到了這個,不知道怎麼回事打開此文件)。
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/examples has finished in 130 ms
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.65/webapps/host-manager
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/host-manager has finished in 80 ms
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.65/webapps/manager
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/manager has finished in 96 ms
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /usr/local/apache-tomcat-7.0.65/webapps/ROOT
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /usr/local/apache-tomcat-7.0.65/webapps/ROOT has finished in 62 ms
Dec 10, 2015 4:46:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 10, 2015 4:46:02 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 10, 2015 4:46:02 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 918 ms
啓動消息調用./startup.sh時:
Using CATALINA_BASE: /usr/local/apache-tomcat-7.0.65
Using CATALINA_HOME: /usr/local/apache-tomcat-7.0.65
Using CATALINA_TMPDIR: /usr/local/apache-tomcat-7.0.65/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
Using CLASSPATH: /usr/local/apache-tomcat-7.0.65/bin/bootstrap.jar:/usr/local/apache-tomcat-7.0.65/bin/tomcat-juli.jar
Tomcat started.
- >'http:// localhost:8080/examples/servlet/PrintServlet' – Mil4n
不幸的是,我得到了同樣的錯誤。 – eager2learn
嘗試使用示例/ servlet/PrintServlet –