0

when I try I submit my form to be handled by the servlet the browser indicates that the requested resource is not available with a HTTP 404 error. The URL looks like:

http://localhost:8080/Website/DateSearchServlet

My XML file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<servlet>
    <servlet-name>DateSearchServlet</servlet-name>
    <servlet-class>DB.DateSearchServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>DateSearchServlet</servlet-name>
    <url-pattern>/Search/*</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

To call the servlet i am using this simple form:

<form name="dateSearch" action="DateSearchServlet" method="post">
    <label for="from">Date From</label>
    <input type="text" id="from" name="from" />
    <label for="to">Date To</label>
    <input type="text" id="to" name="to" />
    <input type="submit" id="submit" value="Submit">
</form>

And finally this is the servlet:

@WebServlet(name = "DateSearchServlet", urlPatterns = {"/Search"})
public class DateSearchServlet extends HttpServlet {

DatabaseConnector dataManager;
boolean dbOK = false;
HomeList homes = new HomeList();

@Override
public void init() {
    dataManager = new DatabaseConnector();
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String dateFrom = request.getParameter("from");
    String dateTo = request.getParameter("to");

    if (dateFrom == null || dateTo == null) {
        dbOK = false;
    } else {
        dbOK = true;
    }//end if

    request.setAttribute("homeList", null);

    if (dbOK) {
        homes = dataManager.getPropertiesSearch(dateFrom, dateTo);
        request.setAttribute("homeList", homes);
        request.getRequestDispatcher("bookings.jsp").forward(request, response);
    } else {
        System.out.println("DBNOTOK");
        //error...
    }
}
}

Thanks

user1851487
  • 547
  • 5
  • 13
  • 28
  • Hi, thanks for the comments, i have had a go at changing the form action as suggested but it still seems to throw the same resource not found error – user1851487 Jan 23 '13 at 10:10

2 Answers2

2

The URL pattern in the web.xml is not configured properly for the servlet you are calling.

So, change the action in the form to the URL Search/DateSearchServlet

Srinivas B
  • 1,821
  • 4
  • 17
  • 35
0

Try this one....

<form name="dateSearch" action="DateSearchServlet.action" method="post">
<label for="from">Date From</label>
<input type="text" id="from" name="from" />
<label for="to">Date To</label>
<input type="text" id="to" name="to" />
<input type="submit" id="submit" value="Submit">

Ram
  • 845
  • 1
  • 13
  • 26