Package de.paulwein.notes

Source Code of de.paulwein.notes.SearchServlet

package de.paulwein.notes;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.paulwein.notes.dao.DAOException;
import de.paulwein.notes.dao.DAOFactory;
import de.paulwein.notes.dao.NotesDAO;
import de.paulwein.notes.pojo.Note;


/**
* SearchServlet
* loads all notes found by the search query
* corresponding to search.jsp
* @author Paul
*
*/
@SuppressWarnings("serial")
public class SearchServlet extends NotesAppServlet
 
  public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    super.doPost(req, resp);
   
    String search = req.getParameter("search");
    if(search == null || search.equals("")){
      errorOccured(resp);
      return;
    }
   
    try {
      DAOFactory df = DAOFactory.getInstance();
      NotesDAO notesDAO = df.getDAO(Note.class, NotesDAO.class);
      List<Note> notes = notesDAO.search(search, user.getUserId());
      req.setAttribute("list", notes);
      RequestDispatcher requestDispatcher = req.getRequestDispatcher(SEARCH_SERVLET + ".jsp");
      requestDispatcher.forward(req, resp);
    } catch (DAOException e) {
      errorOccured(resp);
    } catch (ServletException e) {
      errorOccured(resp);
    }
  }
}
TOP

Related Classes of de.paulwein.notes.SearchServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.