package controleur;
import Metier.Categorie;
import Metier.CategorieService;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class GestionCategorieServlet extends HttpServlet {
private static final String PARAM_ID = "id";
private static final String PARAM_CATEGORIE = "categorie";
public static final String VUE_CATEGORIE = "/privateAcces/GestionCategorie.jsp";
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int id = Integer.parseInt(request.getParameter(this.PARAM_ID));
CategorieService categorieService = Metier.MetierFactory.getCategorieService();
Categorie categorie = categorieService.getById(id);
categorieService.remove(categorie);
this.getServletContext().getRequestDispatcher(this.VUE_CATEGORIE).forward( request, response );
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String newCategorie = request.getParameter(this.PARAM_CATEGORIE);
Categorie categorie = new Categorie(newCategorie);
CategorieService categorieService = Metier.MetierFactory.getCategorieService();
categorieService.add(categorie);
this.getServletContext().getRequestDispatcher(this.VUE_CATEGORIE).forward( request, response );
}
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}