package com.nisum.servlet;

import com.nisum.dao.ProductDAO;
import com.nisum.model.Product;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class ProductServlet extends HttpServlet
{
    private final ProductDAO productDAO = new ProductDAO();

    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {
        try {
            List<Product> productList = productDAO.findAllActive();
            req.setAttribute("products", productList);
            req.getRequestDispatcher("/jsp/product.jsp").forward(req, res);
        }
        catch (SQLException e)
        {
            throw new ServletException("Cannot fetch products", e);
        }
    }
}

