package oss.ngocminh.lego.service;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import oss.ngocminh.lego.data.Entity;
import oss.ngocminh.lego.persistence.CategoryDAO;
import oss.ngocminh.lego.persistence.ProductDAO;
/**
* Servlet implementation class HomeController
*/
public class HomeController extends AbstractController {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public HomeController() {
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Connection conn = null;
try {
conn = getConnection();
CategoryDAO categoryDAO = new CategoryDAO();
categoryDAO.setConnection(conn);
List<Entity> categories = categoryDAO.list();
request.setAttribute("categories", categories);
ProductDAO productDAO = new ProductDAO();
productDAO.setConnection(conn);
List<Entity> bestSellers = productDAO.findRecentBestSellers(20);
request.setAttribute("bestSellers", bestSellers);
renderView(request, response);
} catch (SQLException e) {
throw new ServletException(e);
} finally {
closeConnectionSupressException(conn);
}
}
}