I'm learning Java Servlets and JSP.
I have the following code:
HelloServlet.jsp
public class HelloServlet extends HttpServlet { private static final long serialVersionUID=1; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("utf-8); RequestDispatcher aDispatcher = request.getRequestDispatcher("file.jsp"); aDispatcher.forward(request,response); } } file.jsp
<!DOCTYPE html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>First JSP</title> </head> <body> Hello!! </body> </html> My web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://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" xmlns:schemaLocation="http://java.sun.som/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Hello</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>Hello Servlet</display-name> <servlet-name>hello</servlet-name> <servlet-class>be.howest.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/urlpattern</url-pattern> </servlet-mapping> </web-app> When I'm running the file on Tomcat, I get the following error:
HTTP Status 404 - /Projectname/file.jsp
type - Status report message - Projectname/file.jsp description - The requested resource is not available. What did I do wrong? because I can't find the solution by myself
file.jsplocated?WEB-INFfolder (it's the normal location in Eclipse)/WEB-INF/file.jsp.<url-pattern>/urlpattern</url-pattern>or the exact url-pattern defined in web.xml. Is itHelloServlet.jsporHelloServlet.java