こんにちは、Web アプリを実行しています。「サーバーで実行」を選択すると、ブラウザーに次のエラーが表示されます。
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>
そして、ここにサーブレットクラスファイルがあります:
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 を使用しています。