SearchServlet.java
上传用户:shen332233
上传日期:2021-09-03
资源大小:7478k
文件大小:1k
源码类别:

Ajax

开发平台:

Java

  1. package ajaxdashboard.servlet;
  2. import ajaxdashboard.domain.SearchResult;
  3. import ajaxdashboard.service.SearchService;
  4. import java.io.*;
  5. import java.util.Collection;
  6. import java.util.Iterator;
  7. import javax.servlet.*;
  8. import javax.servlet.http.*;
  9. public class SearchServlet extends HttpServlet {
  10.     private static final String AJAX_JSP = "/jsp/search/searchAutocomplete.jsp";
  11.     
  12.     protected void processRequest(HttpServletRequest request
  13.                                             , HttpServletResponse response)
  14.                                             throws ServletException, IOException {
  15.         String searchTerm = request.getParameter("searchTerm");
  16.         System.out.println("nnn==========Searching: " + searchTerm);
  17.         SearchService searchService = new SearchService();
  18.         Collection results = searchService.search(searchTerm);
  19.         
  20. //        for(Iterator it = results.iterator(); it.hasNext();) {
  21. //            System.out.println(((SearchResult)it.next()).toString());
  22. //        }
  23.         
  24.         request.setAttribute("results", results);
  25.         request.getRequestDispatcher(AJAX_JSP).forward(request, response);
  26.     }
  27.     
  28.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  29.     throws ServletException, IOException {
  30.         processRequest(request, response);
  31.     }
  32.     
  33.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  34.     throws ServletException, IOException {
  35.         processRequest(request, response);
  36.     }
  37.     
  38. }