Giak79
31-12-2005, 11:42
ciao a tutti,
ho un grosso problema e non riesco a trovare una soluzione.
Sto facendo un progetto per l'università e consiste nel creare un sito dove
poter gestire la registrazione di un utente e i vari acquisti .
il problema sta nella generazione della pagina da una jsp : la pagina
generata mostra gli oggetti presenti nel db e per ognuno di essi viene
generato un pulsante che , se premuto , invia il codice dell'oggetto alla
classe java OrdineCtrServlet ,la quale elabora ed aggiunge nel carrello .
Il problema è questo : ogni pulsante di ogni oggetto se premuto invia il
codice dell'ultimo oggetto inserito nella tabella , ovvero :
Codice |Descrizione |Prezzo |Stile | Zona |Materiale |Quantità| AGGIUNGI
3 bho 100 moderno cucina abete 20 ( pulsante )
5 bella! 1302 antico cucina acero 29 ( pulsante )
89 legno 100 moderno bagno acero 20 ( pulsante )
90 classica 1302 moderno cucina acero 12 ( pulsante )
se clicco sul pulsante prova dell'articolo con codice 3 mi invia il codice
dell'ultimo articolo ovvero 90 .
la pagina html generata è questa :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Catalogo2</title>
</head>
<body>
<h3>Sono le ore:Sat Dec 31 10:52:37 CET 2005 </h3>
<h1>Catalogo per <i>a</i></h1>
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Stile</th>
<th align="right">Zona</th>
<th align="right">Materiale</th>
<th align="right">Quantità</th>
<th align="centre">AGGIUNGI AL CARRELLO</th>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">3</td>
<td align="left">bho</td>
<td align="right">100</td>
<td align="left">moderno</td>
<td align="right">cucina</td>
<td align="left">abete</td>
<td align="right">20</td>
<td align="centre">
numero 0
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">5</td>
<td align="left">bella!</td>
<td align="right">1302</td>
<td align="left">antico</td>
<td align="right">cucina</td>
<td align="left">acero</td>
<td align="right">29</td>
<td align="centre">
numero 1
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">89</td>
<td align="left">legno</td>
<td align="right">100</td>
<td align="left">moderno</td>
<td align="right">bagno</td>
<td align="left">acero</td>
<td align="right">20</td>
<td align="centre">
numero 2
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">90</td>
<td align="left">classica </td>
<td align="right">1302</td>
<td align="left">moderno</td>
<td align="right">cucina</td>
<td align="left">acero</td>
<td align="right">12</td>
<td align="centre">
numero 3
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
</table>
<br>
</body>
</html>
-------------------------------------------
la jsp invece ha questo codice :
<%@ page contentType="text/html"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page errorPage="errore.jsp" isErrorPage="false"%>
<%@ page import="carrello.BeanArticolo" %>
<%@ page import="carrello.BeanOrdine" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Date" %>
<%@ page import="javax.swing.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Catalogo2</title>
</head>
<body>
<% if (session.getAttribute("username") == null) {
pageContext.forward("/index.jsp");
} else { %>
<h3>Sono le ore:<%= new java.util.Date() %> </h3>
<h1>Catalogo per <i><%=session.getAttribute("username")%></i></h1>
<%
BeanOrdine beanOrdine = new BeanOrdine();
%>
<%--<form name="prodotti" action="ordineCtrServlet" method=post>
<form name="prodotti" action="carrelloCtrServlet" method=post> --%>
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Stile</th>
<th align="right">Zona</th>
<th align="right">Materiale</th>
<th align="right">Quantità</th>
<th align="centre">AGGIUNGI AL CARRELLO</th>
</tr>
<%
BeanArticolo articolo = new BeanArticolo();
Vector articoli = articolo.trovaTutti();
Vector appoggio = new Vector();
int i=-1;
Iterator iArticoli = articoli.iterator();
while (iArticoli.hasNext()) {
BeanArticolo art = (BeanArticolo)iArticoli.next();
%>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right"><%=art.getCodice()%></td>
<td align="left"><%=art.getDescrizione()%></td>
<td align="right"><%=art.getPrezzo()%></td>
<td align="left"><%=art.getStile()%></td>
<td align="right"><%=art.getZona()%></td>
<td align="left"><%=art.getMateriale()%></td>
<td align="right"><%=art.getDisponibilita()%></td>
<td align="centre"><%
i++;
appoggio.add(i,art);
JOptionPane.showMessageDialog(null,"codice" +
art.getCodice());
%>
numero <%=i %>
<%
session.setAttribute("prova" ,
(BeanArticolo)appoggio.get(i));
%>
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<% } %>
</table>
<br>
<%--
<input type=submit value="Aggiorna">
<input type=reset value="Cancella">
<br>
</form>
--%>
<br><br><hr><br><br>
//arrivato qui---
<h1>TUTTI I TUOI ORDINI</h1>
bisognerebbe mettere un menù a scroll che contenga la max quatità
acquistabile
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Quantitaà</th>
<th align="right">Costo</th>
<th align="right">Data di acquisto</th>
</tr>
<%
Vector ordini =
beanOrdine.trovaOrdineUtente((String)session.getAttribute("username"));
Iterator iOrdine = ordini.iterator();
int totale =0;
while (iOrdine.hasNext()) {
BeanOrdine ord = (BeanOrdine)iOrdine.next();
totale = totale +
ord.getQuantita()*articolo.trovaArticoloPerId(ord.getCod_prodotto()).getPrezzo();
%>
<tr>
<td align="right"><%=ord.getCod_prodotto()%></td>
<td
align="left"><%=articolo.trovaArticoloPerId(ord.getCod_prodotto()).getDescrizione()%></td>
<td
align="right"><%=articolo.trovaArticoloPerId(ord.getCod_prodotto()).getPrezzo()%></td>
<td align="right"><%=ord.getQuantita()%></td>
<td
align="right"><%=(ord.getQuantita()*articolo.trovaArticoloPerId(ord.getCod_prodotto()).getPrezzo())%></td>
<td align="right"><%=ord.getData()%></td>
</tr>
<% } %>
<td colspan="4"><div align="right">Totale</div></td>
<td align="right"><%=totale%></td>
</table>
<p>MODIFICA I TUOI DATI</p>
<i>ancora da implementare...</i>
LOGOUT APPOSTTO!!!
<p></p>
<form action="Logout" method=post/>
<input type=submit value="Logout">
</form>
<% } %>
<%--
<form name="prodotti" action="carrelloCtrServlet" method=post>
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Stile</th>
<th align="right">Zona</th>
<th align="right">Materiale</th>
<th align="right">Quantità</th>
<th align="centre">AGGIUNGI AL CARRELLO</th>
</tr>
<%
BeanArticolo articolo = new BeanArticolo();
Vector articoli = articolo.trovaTutti();
Iterator iArticoli = articoli.iterator();
while (iArticoli.hasNext()) {
BeanArticolo art = (BeanArticolo)iArticoli.next();
%>
<tr>
<td align="right"><%=art.getCodice()%></td>
<td align="left"><%=art.getDescrizione()%></td>
<td align="right"><%=art.getPrezzo()%></td>
<td align="left"><%=art.getStile()%></td>
<td align="right"><%=art.getZona()%></td>
<td align="left"><%=art.getMateriale()%></td>
<td align="right"><%=art.getDisponibilita()%></td>
<td align="centre"><%
session.setAttribute("prova" , art );
JOptionPane.showMessageDialog(null,"codice" +
art.getCodice());
%>
<form action="OrdineCtrServlet" type=post/><input
type=submit value="acquista"></form></td>
</tr>
<% } %>
</table>
<br>
<%--
<input type=submit value="Aggiorna">
<input type=reset value="Cancella">
--%>
<br>
</form>
--%>
</body>
</html>
------------------------------
il problema potrebbe essere nella creazione della tabella e quindi nella
form creata per ogni oggetto . forse ad ogni form va data un nome diverso?
in tal caso come potrei risolvere il problema ??
grazie infinite per il vostro aiuto!!
Giacomo
ho un grosso problema e non riesco a trovare una soluzione.
Sto facendo un progetto per l'università e consiste nel creare un sito dove
poter gestire la registrazione di un utente e i vari acquisti .
il problema sta nella generazione della pagina da una jsp : la pagina
generata mostra gli oggetti presenti nel db e per ognuno di essi viene
generato un pulsante che , se premuto , invia il codice dell'oggetto alla
classe java OrdineCtrServlet ,la quale elabora ed aggiunge nel carrello .
Il problema è questo : ogni pulsante di ogni oggetto se premuto invia il
codice dell'ultimo oggetto inserito nella tabella , ovvero :
Codice |Descrizione |Prezzo |Stile | Zona |Materiale |Quantità| AGGIUNGI
3 bho 100 moderno cucina abete 20 ( pulsante )
5 bella! 1302 antico cucina acero 29 ( pulsante )
89 legno 100 moderno bagno acero 20 ( pulsante )
90 classica 1302 moderno cucina acero 12 ( pulsante )
se clicco sul pulsante prova dell'articolo con codice 3 mi invia il codice
dell'ultimo articolo ovvero 90 .
la pagina html generata è questa :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Catalogo2</title>
</head>
<body>
<h3>Sono le ore:Sat Dec 31 10:52:37 CET 2005 </h3>
<h1>Catalogo per <i>a</i></h1>
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Stile</th>
<th align="right">Zona</th>
<th align="right">Materiale</th>
<th align="right">Quantità</th>
<th align="centre">AGGIUNGI AL CARRELLO</th>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">3</td>
<td align="left">bho</td>
<td align="right">100</td>
<td align="left">moderno</td>
<td align="right">cucina</td>
<td align="left">abete</td>
<td align="right">20</td>
<td align="centre">
numero 0
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">5</td>
<td align="left">bella!</td>
<td align="right">1302</td>
<td align="left">antico</td>
<td align="right">cucina</td>
<td align="left">acero</td>
<td align="right">29</td>
<td align="centre">
numero 1
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">89</td>
<td align="left">legno</td>
<td align="right">100</td>
<td align="left">moderno</td>
<td align="right">bagno</td>
<td align="left">acero</td>
<td align="right">20</td>
<td align="centre">
numero 2
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right">90</td>
<td align="left">classica </td>
<td align="right">1302</td>
<td align="left">moderno</td>
<td align="right">cucina</td>
<td align="left">acero</td>
<td align="right">12</td>
<td align="centre">
numero 3
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
</table>
<br>
</body>
</html>
-------------------------------------------
la jsp invece ha questo codice :
<%@ page contentType="text/html"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page errorPage="errore.jsp" isErrorPage="false"%>
<%@ page import="carrello.BeanArticolo" %>
<%@ page import="carrello.BeanOrdine" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.Date" %>
<%@ page import="javax.swing.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Catalogo2</title>
</head>
<body>
<% if (session.getAttribute("username") == null) {
pageContext.forward("/index.jsp");
} else { %>
<h3>Sono le ore:<%= new java.util.Date() %> </h3>
<h1>Catalogo per <i><%=session.getAttribute("username")%></i></h1>
<%
BeanOrdine beanOrdine = new BeanOrdine();
%>
<%--<form name="prodotti" action="ordineCtrServlet" method=post>
<form name="prodotti" action="carrelloCtrServlet" method=post> --%>
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Stile</th>
<th align="right">Zona</th>
<th align="right">Materiale</th>
<th align="right">Quantità</th>
<th align="centre">AGGIUNGI AL CARRELLO</th>
</tr>
<%
BeanArticolo articolo = new BeanArticolo();
Vector articoli = articolo.trovaTutti();
Vector appoggio = new Vector();
int i=-1;
Iterator iArticoli = articoli.iterator();
while (iArticoli.hasNext()) {
BeanArticolo art = (BeanArticolo)iArticoli.next();
%>
<tr>
<form name=i action="OrdineCtrServlet" type=get/>
<td align="right"><%=art.getCodice()%></td>
<td align="left"><%=art.getDescrizione()%></td>
<td align="right"><%=art.getPrezzo()%></td>
<td align="left"><%=art.getStile()%></td>
<td align="right"><%=art.getZona()%></td>
<td align="left"><%=art.getMateriale()%></td>
<td align="right"><%=art.getDisponibilita()%></td>
<td align="centre"><%
i++;
appoggio.add(i,art);
JOptionPane.showMessageDialog(null,"codice" +
art.getCodice());
%>
numero <%=i %>
<%
session.setAttribute("prova" ,
(BeanArticolo)appoggio.get(i));
%>
<input name="acquisto" type=submit
value=prova>
</form></td>
</tr>
<% } %>
</table>
<br>
<%--
<input type=submit value="Aggiorna">
<input type=reset value="Cancella">
<br>
</form>
--%>
<br><br><hr><br><br>
//arrivato qui---
<h1>TUTTI I TUOI ORDINI</h1>
bisognerebbe mettere un menù a scroll che contenga la max quatità
acquistabile
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Quantitaà</th>
<th align="right">Costo</th>
<th align="right">Data di acquisto</th>
</tr>
<%
Vector ordini =
beanOrdine.trovaOrdineUtente((String)session.getAttribute("username"));
Iterator iOrdine = ordini.iterator();
int totale =0;
while (iOrdine.hasNext()) {
BeanOrdine ord = (BeanOrdine)iOrdine.next();
totale = totale +
ord.getQuantita()*articolo.trovaArticoloPerId(ord.getCod_prodotto()).getPrezzo();
%>
<tr>
<td align="right"><%=ord.getCod_prodotto()%></td>
<td
align="left"><%=articolo.trovaArticoloPerId(ord.getCod_prodotto()).getDescrizione()%></td>
<td
align="right"><%=articolo.trovaArticoloPerId(ord.getCod_prodotto()).getPrezzo()%></td>
<td align="right"><%=ord.getQuantita()%></td>
<td
align="right"><%=(ord.getQuantita()*articolo.trovaArticoloPerId(ord.getCod_prodotto()).getPrezzo())%></td>
<td align="right"><%=ord.getData()%></td>
</tr>
<% } %>
<td colspan="4"><div align="right">Totale</div></td>
<td align="right"><%=totale%></td>
</table>
<p>MODIFICA I TUOI DATI</p>
<i>ancora da implementare...</i>
LOGOUT APPOSTTO!!!
<p></p>
<form action="Logout" method=post/>
<input type=submit value="Logout">
</form>
<% } %>
<%--
<form name="prodotti" action="carrelloCtrServlet" method=post>
<table border=1>
<tr>
<th align="right">Codice</th>
<th align="left">Descrizione</th>
<th align="right">Prezzo</th>
<th align="right">Stile</th>
<th align="right">Zona</th>
<th align="right">Materiale</th>
<th align="right">Quantità</th>
<th align="centre">AGGIUNGI AL CARRELLO</th>
</tr>
<%
BeanArticolo articolo = new BeanArticolo();
Vector articoli = articolo.trovaTutti();
Iterator iArticoli = articoli.iterator();
while (iArticoli.hasNext()) {
BeanArticolo art = (BeanArticolo)iArticoli.next();
%>
<tr>
<td align="right"><%=art.getCodice()%></td>
<td align="left"><%=art.getDescrizione()%></td>
<td align="right"><%=art.getPrezzo()%></td>
<td align="left"><%=art.getStile()%></td>
<td align="right"><%=art.getZona()%></td>
<td align="left"><%=art.getMateriale()%></td>
<td align="right"><%=art.getDisponibilita()%></td>
<td align="centre"><%
session.setAttribute("prova" , art );
JOptionPane.showMessageDialog(null,"codice" +
art.getCodice());
%>
<form action="OrdineCtrServlet" type=post/><input
type=submit value="acquista"></form></td>
</tr>
<% } %>
</table>
<br>
<%--
<input type=submit value="Aggiorna">
<input type=reset value="Cancella">
--%>
<br>
</form>
--%>
</body>
</html>
------------------------------
il problema potrebbe essere nella creazione della tabella e quindi nella
form creata per ogni oggetto . forse ad ogni form va data un nome diverso?
in tal caso come potrei risolvere il problema ??
grazie infinite per il vostro aiuto!!
Giacomo