无法通过 servlet 访问 jsp 页面

Cannot access jsp page via servlet

src/main/java/com.company.HelloWorldServlet.java

public class HelloWorldServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {
        String message = "hello";
        req.setAttribute("message", message);
        req.getRequestDispatcher("/WEB-INF/page.jsp").forward(req, res);
    }
}

web/WEB-INF/page.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Hello world Servlet + JSP</title>
</head>
<body>
<p>Data from Servlet: ${message}</p>
</body>
</html>

web/WEB-INF/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>HelloWorldServlet</display-name>
    <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>com.company.HelloWorldServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/helloworld</url-pattern>
    </servlet-mapping>
</web-app>

应用程序 运行 在本地主机上的 Tomcat7 服务器上。

访问 http://localhost:8080/HelloWorldServlet/helloworld 得到 404 - /HelloWorldServlet/helloworld.

访问 http://localhost:8080/helloworld 得到 404 - /WEB-INF/page.jsp

为什么我的 .jsp 页面对 servlet 不可见?将 .jsp 文件放入 /web/ 也不会改变任何内容。

我添加了 pom.xml 条目来告诉 Maven 资源和配置文件在哪里,这解决了问题。

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
            </configuration>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/webapp</directory>
        </resource>
    </resources>