嗨,我正在运行我的网络应用程序,当我选择“在服务器上运行”时,我在浏览器中收到此错误:
HTTP Status 404 - /ServletsJSPExample/
--------------------------------------------------------------------------------
type Status report
message /ServletsJSPExample/
description The requested resource is not available.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.47
URL 应该是这样的:
http://localhost:8080/ServletsJSPExample/Serv1
但它是
http://localhost:8080/ServletsJSPExample/
为了清楚起见,当我自己写下地址时一切都很好,但我希望它在我运行我的应用程序时已经存在。
这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ServletsJSPExample</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>
<servlet>
<description></description>
<display-name>ServletExample</display-name>
<servlet-name>ServletExample</servlet-name>
<servlet-class>com.example.tutorial.ServletExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletExample</servlet-name>
<url-pattern>/Serv1</url-pattern>
</servlet-mapping>
</web-app>
这是servlet类文件:
package com.example.tutorial;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletExample extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello Java");
}
}
我正在使用 Tomcat 7 和 Eclipse Juno。