I have a index.jsp file that has two different types of forms
<form action="searchpath" name="searchForm" method="get">
<p>BedType</p>
<select name="bedType">
<jsp:include page="/WEB-INF/embeds/bedType.jsp"/>
</select>
<p>Max Price</p>
<input size="10" maxlength="10" name="mPrice"/>
<br/><br/>
<input name="Reset" type="reset" value="RESET" class="input"/> <input type="submit" class="input" value="SUBMIT"/>
</form>
and
<form action="loginController" method="post" id="loginForm">
Please Login :<input name="username" size="30" maxlength="30"/>
Password : <input name="pass" type="password" size="30" maxlength="30"/>
<input type="submit" value="SUBMIT" class="input"/>
</form>
I thought that the action field type directed to the web.xml <url-pattern>/searchpath</url-pattern> would allow me to direct whatever input information I place in those forms to the servlet of that path. That is, the first form will interact with my searchpath servlet. When I tried submitting a form and printing out information nothing seemed to work and I kept receiving a http 404 error . Can someone please help me out with this?
web.xml :
<servlet-mapping>
<servlet-name>Search</servlet-name>
<url-pattern>/searchpath</url-pattern>
</servlet-mapping>
inside my search.java servlet :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Static Servlet</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<h1>WTF</h1>");
out.println("</BODY>");
out.println("</HTML>");
Check browser URL. You are missing context.
Let Say, You are running at http://localhost:8080/test/index.jsp where
testis your context path.So, When calling Servlet It should be like http://localhost:8080/test/searchpath.
In your case, Its not like that.
So, Adding cotextpath will solve your problem.
e.g.
action="<%=request.getContextPath()%>/searchpath"