1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();
List<String> listeProduits = (List<String>) session.getAttribute("produits");
if (listeProduits == null) {
listeProduits = new ArrayList<String>();
session.setAttribute("produits", listeProduits);
}
pw.print(session.getId() + "<br/>");
if (request.getParameter("action").equalsIgnoreCase("ajouter")) {
listeProduits.add(request.getParameter("produit"));
pw.print("Produit ajouté avec succés");
}else{
for (String prod : listeProduits) {
pw.println("<li>" + prod + "</li>");
}
request.setAttribute("pan",listeProduits);
RequestDispatcher dispatch = request
.getRequestDispatcher("/panier.jsp");
dispatch.forward(request, response);
}
} |
Partager