le domande che sto x farvi sembreranno banali,anch'io me ne accorgo ma non so xkè non riesco a risolverle.ho un carrello della spesa,affianco ad ogni elemento del carrello c'è un link x eliminarlo.ma non va.posto sia la classe java sia la pagina jsp.
Carrello.java
ListaCarrello.jspcodice:package Prodotti; import java.util.*; public class Carrello{ Vector elementi = new Vector(); public void deleteProdotto(String cod){ Enumeration enumElem=getElementi(); while(enumElem.hasMoreElements()){ Prodotto prod=(Prodotto)enumElem.nextElement(); if(prod.getintId().equals(cod)){ elementi.removeElement(prod); break; } } } public Enumeration getElementi(){ return elementi.elements(); }}
i problemi sono: 1)nella pagina jsp non posso usare: int cod = request.getParameter(cod); xkè getParameter non si può usare con gli int ma non so come sostituirlo. 2) The method deleteProdotto(String) in the type Carrello is not applicable for the arguments (int) 3)ho usato equals in carrello.java x gli int ma lo potrei sostituire con == sperando che funzioni cmqcodice:<%@ page language="java" import="java.util.*" import="java.lang.*" import="Prodotti.*"%> <html> <head> <title>'ListaCarrello.jsp'</title> <script type="text/javascript"> function AllaRicerca() { location.href = ("ricerca.jsp"); } </script> </head> <body> <h2 align="center">Il tuo carrello della spesa</h2> <% Prodotto prod = new Prodotto(); List articolo = new Vector(); articolo=(Vector)session.getAttribute("Prodotto"); String strClick = request.getParameter("B3"); if (strClick != null){ articolo.clear(); articolo=null; %> <div align="center"> <input type="button" value="Torna in Ricerca" onclick="AllaRicerca()"> </div> <% return; } String name = request.getParameter("name"); Carrello carr = new Carrello(); if(name.equals("deleteItem")) { int cod = request.getParameter(cod); carr.deleteProdotto(cod); } if (request.getParameter("idProd") != null && request.getParameter("prod")!= ""){ String strId = request.getParameter("idProd"); Integer appoggio = null; int intId = appoggio.parseInt(strId); prod.setintId(intId); String strQuant = request.getParameter("Quantità"); Integer app = null; int intQuant = app.parseInt(strQuant); prod.setintQuantità(intQuant); String strNome = request.getParameter("NomeProd"); prod.setstrNome(strNome); String strPrezzo = request.getParameter("PrezzoProd"); Float appog = null; float fltPrezzo = appog.parseFloat(strPrezzo); prod.setfltPrezzo(fltPrezzo); articolo.add(prod); session.setAttribute("Prodotto", articolo); } List ListaGet = new Vector(); ListaGet = (Vector)session.getAttribute("Prodotto"); %> <div align="center"> <form action="ListaCarrello3.jsp" method="post"> <table border=0 cellpadding=0 cellspacing=0> <% for (int i=0; i<ListaGet.size(); i++){ %> <tr> <td width="100"> <%= ((Prodotto)ListaGet.get(i)).getstrNome() %> </td> <td width="100"> Euro <%=((Prodotto)ListaGet.get(i)).getfltPrezzo() %> </td> <td width="100"> Quantità: <%=((Prodotto)ListaGet.get(i)).getintQuantità() %> </td> <td> <a href="ListaCarrello3.jsp?name=deleteItem&cod=<%=((Prodotto)ListaGet.get(i)).getintId()%>"> Elimina</a> </td> </tr> <% } %> <tr> <td> <input type="button" value="Torna in Ricerca" onclick="AllaRicerca()"> </td> <td> <input type="submit" value="Svuota carrello" name="B3"> </td> </tr> </table> </form> </div> </body></html>![]()

Rispondi quotando