0

So i have a post form which calls a Servlet to perform a search but the problem is that when i push the submit button it's completely unresponsive. Although when used in the same form in a different .jsp page it works as it should. If it had something to do with the servlet mapping there would be an error page from the tomcat server but i do not get such an error page. It's just completely unresponsive.

My HTML form:

   <form action="AnonSearchServlet" class="form-inline" method="post">
      <input type="search" name="location" class="form-control input-lg" placeholder="Destination, City, Address" required>
      <div class="input-group">
        <input type="search" class="form-control input-lg" placeholder="When" name="daterange" value="" required/>
        <div class="input-group-addon">
          <span class="glyphicon glyphicon-calendar"></span>
        </div>
      </div>
      <input style="width: 20%; height: 46px" type="number" min="1" name="accomodates" class="form-control" placeholder="Guests" required>
      <button type="submit" class="btn btn-danger btn-lg">Search</button>
    </form>

My Servlet:

public class AnonSearchServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String start_date;
        String end_date;
        String date_range = request.getParameter("daterange");
        UserBean user = new UserBean();
        String[] tokens = date_range.split(" ");
        start_date = tokens[0];
        end_date = tokens[2];

        try {
            HttpSession session = request.getSession(true);
            user.setUserID(0);
            System.out.println(user.getUserID());

            ResultSet search_rs = null;
            SearchBean search_bean = new SearchBean();

            search_bean.setUserId(user.getUserID());
            search_bean.setLocation(request.getParameter("location"));
            System.out.println(request.getParameter("location"));
            search_bean.setStreet(request.getParameter("location"));
            search_bean.setNeighbourhood(request.getParameter("location"));
            search_bean.setAccomodates(request.getParameter("accomodates"));
            search_bean.setStartDate(start_date);
            search_bean.setEndDate(end_date);

            search_bean = SearchDAO.search(search_bean);
            session.setAttribute("current_search", search_bean);
            response.sendRedirect("searchResults.jsp");


        } catch (Throwable thException) {
            System.out.println(thException);
        }
    }
}

And my web.xml:

    <servlet>
        <servlet-name>AnonSearchServlet</servlet-name>
        <servlet-class>Servlets.AnonSearchServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AnonSearchServlet</servlet-name>
        <url-pattern>/AnonSearchServlet</url-pattern>
    </servlet-mapping>
Ahmad Al-Kurdi
  • 2,248
  • 3
  • 23
  • 39
CharisAlex
  • 93
  • 12

2 Answers2

0

@CharisAlex here is the problem in your jsp page <button> tag doesn't submit form action so you have to modify your code

<button type="submit" class="btn btn-danger btn-lg">Search</button>`

replace into

<input type='submit' class='btn btn-danger btn-lg' value="Search" />
  • Thanks for the suggestion. But it was actually a segment of JavaScript code that prevented the posting of the form. – CharisAlex Sep 19 '17 at 13:11
-1

Try to use

<input type="submit" value="submit">

instead of using

<button type="submit" class="btn btn-danger btn-lg">Search </button> 
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49