プログラミング初心者で申し訳ないです。eclipseでjavaサーブレットプログラムを書いているのですが、次のコードが実行できません。
package名 sample クラス名 Sample1
package sample; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/Sample1") public class Sample1 extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{ response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Hello World!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello World!</h1>"); out.println("</body>"); out.println("</html>"); out.close(); } }
エラーの説明
「404-notfound /sample/Sample1 The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.」
アクセスしたURL http://localhost:8080/sample/Sample1
動的プロジェクトでプロジェクトを作成して、サーバーを追加して、サーバーで実行で実行しました。初心者なのでよくわからず、サーバーの設定などはあまりいじってません。とあるサイトの解説どおりにやってみました。なにか修正する必要がありましたら、コメントでよろしくお願いします。
回答2件
あなたの回答
tips
プレビュー