Search code examples
javajspservletsrequestdispatcher

404 - Not Found Error RequestDispatcher jsp forward


I am trying to forward a Servlet to a JSP and I get this error when I click on the button that calls the doGet() that forwards into the JSP

Type Status Report

Message /servlet/crossfit/WOD

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

This is my Servlet code:

RequestDispatcher rd getServletContext().getRequestDispatcher("/app/crossfit/amrap.jsp");
        rd.forward(request, response);

This is the mapping in my web.xml file

 <servlet>
    <servlet-name>WOD</servlet-name>
    <description>Handle the workout generator and saver</description>
    <servlet-class>servlet.activity.crossfit.WOD</servlet-class>
</servlet>
  <servlet-mapping>
    <servlet-name>WOD</servlet-name>
    <url-pattern>/servlet/activity/crossfit/WOD</url-pattern>
</servlet-mapping>

> <servlet-mapping>
>         <servlet-name>AmrapServlet</servlet-name>
>         <url-pattern>/app/crossfit/amrap.jsp</url-pattern>
> </servlet-mapping>


> <servlet>
>     <servlet-name>AmrapServlet</servlet-name>
>     <jsp-file>/app/crossfit/amrap.jsp</jsp-file> </servlet>

Project Structure


Solution

  • In the request the path activity is missing. Requested path is /servlet/crossfit/WOD and in your web.xml you have /servlet/activity/crossfit/WOD

    Adjust in the code where you have the button your request path from /servlet/crossfit/WOD to /servlet/activity/crossfit/WOD