예제 #1
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      HttpSession session = request.getSession();
      User user = new User();
      user = (User) session.getAttribute("user");

      String name = request.getParameter("name");
      String address = request.getParameter("address");
      String comment = request.getParameter("comment");
      Subscriber subscriber = new Subscriber();
      subscriber.setName(name);
      subscriber.setAddress(address);
      subscriber.setComment(comment);

      Log log = new Log();
      log.createSubscriber(user, subscriber.getName(), subscriber.getAddress());
      DaoFactory.getLogDao().create(log);

      Long id = DaoFactory.getSubscriberDao().create(subscriber);

      request.setAttribute("subscriber", subscriber);

      RequestDispatcher view = request.getRequestDispatcher("createPhone.jsp");
      view.forward(request, response);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
예제 #2
0
 /**
  * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  *
  * @param request servlet request
  * @param response servlet response
  * @throws ServletException if a servlet-specific error occurs
  * @throws IOException if an I/O error occurs
  */
 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   try {
     String sort = "";
     String order = "";
     sort = request.getParameter("sort");
     order = request.getParameter("order");
     if (!"name".equals(sort) && !"address".equals(sort) && !"comment".equals(sort)) sort = "name";
     if (!"asc".equals(order) && !"desc".equals(order)) order = "asc";
     Collection<Subscriber> listSubscriber = DaoFactory.getSubscriberDao().getAll(sort, order);
     request.setAttribute("subscribers", listSubscriber);
     RequestDispatcher view = request.getRequestDispatcher("viewSubscribers.jsp");
     view.forward(request, response);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }