Example #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 {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
      /* TODO output your page here. You may use following sample code. */
      FactoryProduto fp = new FactoryProduto();
      List produtos = new ArrayList<Produto>();
      produtos = fp.selectProdutoByCategoria("Electronicos");

      String nextJsp = "/mProdutos.jsp";
      request.setAttribute("produtos", produtos);
      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJsp);
      dispatcher.forward(request, response);
    }
  }
  /**
   * 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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {

      FactoryProduto fp = new FactoryProduto();
      List produtos = new ArrayList<Produto>();

      produtos = fp.selectProdutosByCategoria("impressora");

      String nextJsp = "/cImpressoras.jsp";
      request.setAttribute("produtos", produtos);
      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJsp);
      dispatcher.forward(request, response);

    } finally {
      out.close();
    }
  }