Bonjour à tous
je suis débutante en JAVA J2EE et ma petite application consiste à :
1- dans ma première page index .jsp
---> afficher liste des produits disponibles
---> l'utilisateur peur cocher le produit qu il veut acheter (pas de choix de quantité) == devant chaque produit un champ checkBox
2 - l'utilisateur saisi son nom, adresse et choix du mode de livraison
3- il valide par le bouton
4- page ajoutPanier.jsp : on affiche les choix de mon utilisateur sous fous forme d'une facture .

REMARQUE : j'utilise pas la base de données : mes objets sont instanciés dans mon code

je mets ma classe : index.jsp
panier.jsp
servlet : ajoutPanier.java
class Produit et panier

je suis coincée sur la récupération des valeurs et leur affichage
Merci

index.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
 
 <%@ page         import ="magasin.controller.*" %>  
  <%@ page         import ="magasin.model.*" %>  
  <%@ page        import ="java.util.ArrayList" %> 
  <%@ page        import ="java.util.List" %> 
  <%@page session="true" %>
 
 <%
 
  Client c = new Client ("Nahla VILLa","137 rue de g de Gaulle 94350 V /S Marne");
  Produit tv1 = new Tv ("Samsung",399,24,24, " Tv plasma LED");
  Produit tv2 = new Tv ("Samsung",1200,34,56 ," Tv 4K LED");
  Produit tv3 = new Tv ("Sony",899,23, 77," Tv plasma LED");
  Produit tv4 = new Tv ("LG",499,55, 45," Tv plasma LCD"); 
  List<Produit> produits = new ArrayList<Produit>();
  produits.add(tv1);
  produits.add(tv2);
  produits.add(tv3);
  produits.add(tv4);
 %>
<html>
<head>
<meta charset="UTF-8">
<title> afficherListe</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<h3>Magasin Electromenager</h3>
<h5> Liste produits </h5>
 
<fieldset>
<form action="AjouterPanier" method="post">
<div style="text-align">
<%!int id=0 ; %>
<div stryle="text-align: right">
 <!-- Pannier : mon image du panier --> 
<%-- <input name="listp" type="number" size="5" value="<% id = id +1 ; %> " /> --%>
</a>
</div>
 <div class="col-md-8"> 
<table border="2" class="table">
<thead>
<tr>
<th text-align="center" scope="col">PRODUIT</th>
 
<th text-align="center"scope="col">PRIX</th>
<th text-align="center"scope="col">QUANTITE</th>
</tr>
</thead>
<tbody>
<%   for (Produit produit : produits) { %>
<tr scope="row">
<td class="form-control is-valid" name="produit"><%= produit.getDescription() %> pouce </td>
<td class="form-control is-valid" ><%= produit.getPrix() %> euros </td>
<td class="form-control is-valid" ><input   type="checkbox" size="5" name="choix" value=<%= id %> ></input></td>
 
<%-- <td><%= produit.get %></td> --%>
</tr>
<%} %>
</tbody>
</table>
</div>
</fieldset>
<br><br>
<fieldset>
 
 
<h3> Mode de livraison </h3><br>
<div class="col-md-8">
<table border="2" class="table">
<thead border="0" class="table">
<th><p>Livraison a domicile sous 24 heures pour 25 euros</p>
<th><input type="radio" name="express" /></th>
 
 
</thead>
<tbody>
<tr>
 <th><p>Livraison au point de relais pour 6 euros </p>
<th><input type="radio" name="relais" /></th>
 
</tr>
<tr>
<th><p>Retrais au magasin </p>
<th> <input type="radio" name="magazin" /></th></tr>
</tbody>
</table>
</div>
<br>
 
 
 
<div class="col-md-8">
<table>
<h3> Saisir vos coordonnées : </h3><br>
<thead>
<th><label for="validationServer01">Nom & Prénom</label></th>
<th> 
 
<input type="text" name="fullname" placeholder=" fullname" class="form-control is-valid" >
 
</input>
</th>
</thead>
<tbody>
<tr>
 
<td><label for="validationServer01">Adresse</label></td>
<td>
 
<input type="text" name="adresse"placeholder="adresse" class="form-control is-valid" >
 
</input>
</td>
</tr>
</tbody>
</table>
</div>
<p style="text-align: center;">
<button name="valider" > VALIDER COMMANDE </button>
</form>
</fieldset>
 
 
 
</body>
</html>

panier.jsp

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="magasin.controller.* " %>
    <%@ page import="magasin.model.* " %>
   <%@ page        import ="java.util.ArrayList" %> 
  <%@ page        import ="java.util.List" %> 
<!DOCTYPE html>
<html>
</head>
    <body>
    <h1>Facture</h1>
    <p> Magasin Sim plon Shop<p> 
    <p> 55 rue Viencennes 93100 Montreuil
    <p> Tel: (+33) 1 34 65 54 11<br>
    <p> Fax : (+33)1 34 65 54 11<br>
    <p>Email: shop@sim plon.co
    <p>----------------------------------------------------------------------------------------------------------------------------------------<p><br>
    <h2>A l'ordre de :</h2>
 
    <!-- recuper mon client  -->
    <p>  <% String fullname = (String) request.getAttribute("fullname") ;
            out.println(fullname) ; 
            %><br><br>
            <%  
             String adresse = (String) request.getAttribute("adresse");
        
              out.println(adresse); %> 
          </p>
    </form>
        <div style="text-align: center;">
            <h2 >Votre Pannier</h2>
 
        </div>
        <table border="1">
            <thead>
                <tr>
                    <th>Quantité</th>
                    <th>Produit</th>
                    <th>Prix</th>
 
                </tr>
            </thead>
            <tbody>
                <%! double prixTotal = 0;%>
                <%
                 
                List<Integer> panier = (List<Integer>) session.getAttribute("MonPanier");
                for (int i = 0; i < panier.size(); i++) {
                        int refId = ((Integer) panier.get(i)).intValue();
 
                %>
 
 
                <tr>
                    <td><%  String qtes =(String) request.getAttribute("qtes") ;
                    out.println(qtes) ; %></td>
                    <td><%  String produits =(String) request.getAttribute("produits") ;
                    out.println(produits);%> </td>
                    <td><%  out.println(produits) ; }%> </td>
 
                </tr>
 
            </tbody>
        </table>
        <h2 style="text-align: center;">Total: </h2>
 
    </body>
</html>


ajoutPanier .java
Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package magasin.controller;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import magasin.model.Client;
import magasin.model.Livraison;
import magasin.model.Panier;
import magasin.model.Produit;
import magasin.model.RelaisLivraison;
import magasin.model.Tv;
 
@WebServlet(name = "/AjouterPanier", urlPatterns = { "/AjouterPanier" })
 
public class AjouterPanier extends HttpServlet {
	private static final long serialVersionUID = 1L;
 
	List<Panier> paniers = new ArrayList<>();
 
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
 
		request.setCharacterEncoding("UTF-8");
 
		/*
		 * RequestDispatcher rd = request.getRequestDispatcher("panier.jsp") ;
		 * 
		 * String fullname = request.getParameter("fullname") ; String adresse =
		 * request.getParameter("adresse") ;
		 * 
		 * 
		 * 
		 * int id = Integer.parseInt(request.getParameter("id"));
		 * 
		 * paniers = (List<Panier>) request.getAttribute("listpr"); for (Panier p1 :
		 * paniers) { if (p1.getProduit().getId() == id) { p1.setQte(p1.getQte() + 1);
		 * 
		 * } } rd.forward(request, response) ; request.setAttribute("listpr", paniers);
		 * 
		 * 
		 * response.sendRedirect("panier.jsp");
		 */
 
	}
 
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		List<Produit> produits = new ArrayList<Produit>();
 
		request.setCharacterEncoding("UTF-8");
 
		String message = null ;
 
		// recuperer mes valeurs  
		int qte  = Integer.parseInt(request.getParameter("qte")); 
		String  produit = request.getParameter("produit");
		String fullname = request.getParameter("fullname");
		String adresse = request.getParameter("adresse");
		// String modeLivrason =  request.getParameter("modeLivraison");
		request.setAttribute("fullname", fullname);
		request.setAttribute("adresse", adresse);
 
 
		HttpSession session = request.getSession(true);
		List<Integer> panier = (List<Integer>)session.getAttribute("MonPanier");
		// recuper mes champs de quantité !! 
 
		if (panier == null) {
			panier = new ArrayList<Integer>();
			session.setAttribute("MonPanier", panier);
			}
			//  Récupération des choix et ajout dans le panier
			String selection[] = request.getParameterValues("choix");
			for (int i = 0; i < selection.length; i++) {
			panier.add(new Integer(selection[i]));
			}
 
		RequestDispatcher rd = request.getRequestDispatcher("panier.jsp");
        rd.forward(request, response);
		}
 
 
	protected void processRequest(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
 
 
 
 
 
 
 
 
	}
}


produit.java
Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package magasin.model;
 
import java.util.ArrayList;
import java.util.List;
 
public abstract class Produit {
 
	private String nom ;
	private double prix ;
	private int id ;
 
 
 
	public Client client ;
	public Livraison livraison;
 
	public Produit() {}
 
	public Produit(String nom , double prix , int id) {
 
		this.nom=nom;
		this.prix=prix;
		this.id=id;
	}
 
 
	public String getNom() {
		return nom;
	}
 
 
	public double getPrix() {
		return prix;
	}
 
 
	public int getId() {
		return id;
	}
 
 
 
 
	public Livraison getLivraison() {
		return livraison;
	}
 
 
	public void setLivraison(Livraison livraison) {
		this.livraison = livraison;
	}
 
 
	public Client getClient() {
		return client;
	}
 
 
	public Produit (Client client , Livraison livraison) {
		this.client = client;
		this.setLivraison(livraison);
	}
 
	public abstract String getDescription() ;
 
	public List<Produit> getAllProduit(){
		List<Produit> produits = new ArrayList<Produit>();
		return produits;
	}
	public void achterProduit(Produit produit , Integer quantite) {}
 
	public int getById(int id) {
		// TODO Auto-generated method stub
		return id;
	};
	public boolean equals(Object o) {
		return nom.equals(((Produit) o).nom);
	}
}

paniere.java
Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package magasin.model;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map.Entry;
 
public class Panier  {
    private Produit produit;
    private Client client ;
    private Livraison livraison ;
    public Livraison getLivraison() {
		return livraison;
	}
 
	public void setLivraison(Livraison livraison) {
		this.livraison = livraison;
	}
	private int qte;
    private ArrayList<Produit> produits = new ArrayList<Produit>();
 
 
    public Panier(Client client ,Produit produit, int qte) {
        this.client=client;
    	this.produit = produit;
        this.qte = qte;
    }
 
    public Client getClient() {
		return client;
	}
 
	public void setClient(Client client) {
		this.client = client;
	}
 
	public ArrayList<Produit> getProduits() {
		return produits;
	}
 
	public void setProduits(ArrayList<Produit> produits) {
		this.produits = produits;
	}
 
	public Produit getProduit() {
        return produit;
    }
 
    public void setProduit(Produit produit) {
        this.produit = produit;
    }
 
    public int getQte() {
        return qte;
    }
 
    public void setQte(int qte) {
        this.qte = qte;
    }
    public void ajout(Produit p, int qte ) {
 
    	produits.add(produit);
    }
    public void supp(Produit p) {
    	produits.remove(produit);
    }
    public int calculerPanier() {
		int total = 0;
 
			for( Produit produit : produits ) {
			total += produit.getPrix() * this.qte ;}
 
		return total;
	} 
 
}

merci infiniment