94 lines
2.5 KiB
Java
94 lines
2.5 KiB
Java
import java.io.*;
|
|
|
|
import javax.servlet.*;
|
|
import javax.servlet.http.*;
|
|
|
|
import java.lang.*;
|
|
import java.util.Vector;
|
|
import com.articles.Article;
|
|
import com.articles.ArticlePanier;
|
|
import com.gestionnaires.Erreur;
|
|
import com.gestionnaires.GestionnairePanier;
|
|
|
|
public class Panier
|
|
extends HttpServlet
|
|
{
|
|
com.gestionnaires.GestionnaireArticles gestArts = null;
|
|
|
|
private void traiteRequeteHttp(HttpServletRequest request, HttpServletResponse response)
|
|
throws ServletException, IOException
|
|
{
|
|
HttpSession session = request.getSession(true);
|
|
Vector<ArticlePanier> vArtsPan = null;
|
|
Vector<Article> vArts = new Vector<Article>();
|
|
Article tmpArt = null;
|
|
String sAction;
|
|
String sPageAffichage;
|
|
|
|
GestionnairePanier panier = (GestionnairePanier)session.getAttribute("caddy");
|
|
if ( panier == null )
|
|
{
|
|
panier = new GestionnairePanier();
|
|
|
|
session.setAttribute("caddy", panier) ;
|
|
}
|
|
|
|
sAction = request.getParameter("action");
|
|
if (sAction == null)
|
|
{
|
|
;
|
|
}
|
|
else if (sAction.equals("add"))
|
|
{
|
|
panier.ajouterAchat(request.getParameter("artRef"), Integer.parseInt(request.getParameter("artQuant")));
|
|
}
|
|
else if (sAction.equals("del"))
|
|
{
|
|
panier.enleverAchat(request.getParameter("artRef"));
|
|
}
|
|
|
|
vArtsPan = panier.donneContenu();
|
|
|
|
for (int i=0; i<vArtsPan.size(); i++)
|
|
{
|
|
tmpArt = new Article();
|
|
tmpArt.setRef(vArtsPan.get(i).getRef());
|
|
tmpArt.setQuantite(vArtsPan.get(i).getQuantite());
|
|
tmpArt.setCateg("cat"+i);
|
|
tmpArt.setDescription("desc"+1);
|
|
vArts.add(tmpArt);
|
|
}
|
|
|
|
if (!vArts.isEmpty())
|
|
{
|
|
request.setAttribute("articles", vArts);
|
|
|
|
sPageAffichage = "/contenuPanier.jsp";
|
|
}
|
|
else
|
|
{
|
|
sPageAffichage = "/panierVide.jsp";
|
|
}
|
|
|
|
ServletContext ctx = getServletContext();
|
|
RequestDispatcher rd = ctx.getRequestDispatcher(sPageAffichage);
|
|
rd.forward(request,response);
|
|
}
|
|
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
throws ServletException, IOException
|
|
{
|
|
this.traiteRequeteHttp(request, response);
|
|
}
|
|
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
|
throws ServletException, IOException
|
|
{
|
|
this.traiteRequeteHttp(request, response);
|
|
}
|
|
|
|
public String getServletInfo() {
|
|
return "Gestion du panier";
|
|
}
|
|
}
|