I am new to web development and am working on a web application that will use servlets and JSPs and I created both my servlet and my JSP but I am having a hard time getting the servlet to forward the request to the JSP.
In my main
page, there is a <form>
that uses a get
method and the action is pointed to my servlet (SelectSupportUnit.do
):
<form method="get" action="SelectSupportUnit.do">
And in my servlet, it forwards the results from my JDBC Query to a JSP:
request.setAttribute("suppUnitList", suppUnitList);
RequestDispatcher view = request.getRequestDispatcher("QueryResults.jsp");
view.forward(request, response);
And in my web.xml file it declares the JSP (this is what it says to do in the Head First Servlets and JSPs book when forwarding a request from your servlet to a JSP):
<servlet>
<servlet-name>SelectSupportUnit</servlet-name>
<jsp-file>/QueryResults.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>SelectSupportUnit</servlet-name>
<url-pattern>/QueryResults.jsp</url-pattern>
</servlet-mapping>
When I run this (using Eclipse IDE and Tomcat v7 container) it is giving me HTTP status 404
. And says it cannot find my servlet (SelectSupportUnit.do
).
That would make it appear as if in the <form>
element that calls the servlet, you should call the JSP, but if I do this won't it bypass the servlet?
My form
looks like this:
My element looks like this now:
<form target="_blank" method="get" action="${PageContext.request.contextPath}/SelectSupportUnit">