すべて、私はJava Web開発の初心者です。テストでサーブレットを実装しようとしています。しかし、作成したサーブレットが機能しないことがわかりました。何かを逃したかどうかはわかりませんでした。レビューするのを手伝ってください。ありがとう。
私がこれまでに行ったことは次のとおりです。
- オプション
で
Dynamic Web Project
名前付きを作成しました。SecondWeb
Generate web.xml DD
- パッケージの下に
Servlet
名前を追加しました。と の値 を設定します。ルートの下のすべての URL パターンで機能することを願っています。HelloServlet
com.example.servlets
URL Mapping
/HelloServlet
/*
これがそのコードです。
package com.example.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: HelloServlet
*
*/
public class HelloServlet extends javax.servlet.http.HttpServlet
implements javax.servlet.Servlet {
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public HelloServlet() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().write("Hello, world!");
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
そして、私もindex.jsp
テストに参加しました。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Title</title>
</head>
<body>
<% java.util.Date d = new java.util.Date(); %>
<h1>
Today's date is <%= d.toString() %> and this jsp page worked!
</h1>
</body>
</html>
私が期待Hello world
したのは、index.jsp
URLまたは. しかし、うまくいかないようです。なんで?ありがとう。HTML
http://localhost:8080/SecondWeb
http://localhost:8080/SecondWeb/index.jsp
HelloServlet