「hostname:8080/WebTest1/users」にアクセスしようとすると、次のエラーが表示されます。
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/7.0.42
私の 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>WebTest1</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>
<!-- Added these for the freemarker templates to work with the servlet -->
<servlet-name>freemarker</servlet-name>
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
<!-- FreemarkerServlet settings: -->
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>NoCache</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>ContentType</param-name>
<param-value>text/html; charset=UTF-8</param-value>
<!-- Forces UTF-8 output encoding! -->
</init-param>
<!-- FreeMarker settings: -->
<init-param>
<param-name>template_update_delay</param-name>
<param-value>0</param-value>
<!-- 0 is for development only! Use higher value otherwise. -->
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<!-- <param-value>ISO-8859-1</param-value> -->
<param-value>UTF-8</param-value>
<!-- The encoding of the template files. -->
</init-param>
<init-param>
<param-name>number_format</param-name>
<param-value>0.##########</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>hello_servlet</servlet-name>
<servlet-class>com.fivetech.freemarker.examples.HelloServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>user_servlet</servlet-name>
<servlet-class>com.fivetech.webtest1.servlets.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello_servlet</servlet-name>
<url-pattern>/hello-ftl</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>user_servlet</servlet-name>
<url-pattern>/users</url-pattern>
</servlet-mapping>
<!--
Prevent the visiting of MVC Views from outside the servlet container.
RequestDispatcher.forward/include should and will still work. Removing
this may open security holes!
-->
<security-constraint>
<web-resource-collection>
<web-resource-name>FreeMarker MVC Views</web-resource-name>
<url-pattern>*.ftl</url-pattern>
</web-resource-collection>
<auth-constraint>
<!-- Nobody is allowed to visit these -->
</auth-constraint>
</security-constraint>
私の Bean User.java は次のようになります。
package com.fivetech.webtest1.models;
public class User {
public String firstname;
public String lastname;
public String username;
public String password;
public User(String firstname, String lastname, String username, String password) {
this.firstname = firstname;
this.lastname = lastname;
this.username = username;
this.password = password;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void setUsername(String username) {
this.username = username;
}
public void setPassword(String password) {
this.password = password;
}
public String getFirstname() {
return this.firstname;
}
public String getLastname() {
return this.lastname;
}
public String getUsername() {
return this.username;
}
public String getPassword() {
return this.password;
}
}
サーブレット クラス (UserServlet.java) は次のようになります。
package com.fivetech.webtest1.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UserServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/users.ftl").forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//nothing here yet
}
}
私はこれから404を持っていますが、何か小さなものが欠けていると確信していますが、まだ理解できていません. 何か案は?