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>
The application is running on Tomcat7 server on localhost.
Accessing http://localhost:8080/HelloWorldServlet/helloworld
gives a 404 - /HelloWorldServlet/helloworld
.
Accessing http://localhost:8080/helloworld
gives a 404 - /WEB-INF/page.jsp
Why isn't my .jsp page visible to the servlet? Putting the .jsp file in /web/ doesn't change anything either.