duke_79
05-08-2008, 20:09
Salve a tutti!! Premetto chesono alle prime armi con jsp ,vorrei sapere come faccio a salvare la scelta di una select option nella request e a stamparla nella pagina successiva??? Ho provato cosė ma..... non mi funziona
<form method="post" action="estrai.jsp">
<fieldset>
<legend>Scelta Prodotti</legend>
<label for="prodotto"> </label>
<table>
<tr>
<td>Prodotto </td>
<select name="prodotto" id="prodotto">
<option>Seleziona un prodotto</option>
<%
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver);
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/basedati","root","password");
st = conn.prepareStatement("SELECT codice,tipo,descrizione FROM prodotti order by tipo ");
rs = st.executeQuery();
while(rs.next()){
Prodotto p= new Prodotto();
p.setCodice(rs.getString("codice"));
p.setTipo(rs.getString("tipo"));
p.setDescrzione(rs.getString("descrizione"));
%>
<option value="a1"> <%=p.tipo%> - <%=p.descrizione%> </option>
<%
}
}catch (SQLException sqle) {
throw new SQLException("Errore persistenza" +sqle);
}finally {
if(conn != null)
rs.close();
st.close();
conn.close();
}
%>
</td>
</tr>
</select>
</table>
<input type="submit" value="view"/>
</fieldset>
</form>
<%
String prodotto = request.getParameter( "prodotto" );
%>
nella pagina successiva ho provato a scrivere cosė..
<%
String prodotto =(String)request.getAttribute( "prodotto");
// String prodotto = (String)request.getAttribute("prodotto");
out.println("<p>"+prodotto+"</p>");
%>
mi stampa null Dove sbaglio??????
Grazie in anticipo!!!
<form method="post" action="estrai.jsp">
<fieldset>
<legend>Scelta Prodotti</legend>
<label for="prodotto"> </label>
<table>
<tr>
<td>Prodotto </td>
<select name="prodotto" id="prodotto">
<option>Seleziona un prodotto</option>
<%
Connection conn = null;
PreparedStatement st = null;
ResultSet rs = null;
String driver = "org.gjt.mm.mysql.Driver";
Class.forName(driver);
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/basedati","root","password");
st = conn.prepareStatement("SELECT codice,tipo,descrizione FROM prodotti order by tipo ");
rs = st.executeQuery();
while(rs.next()){
Prodotto p= new Prodotto();
p.setCodice(rs.getString("codice"));
p.setTipo(rs.getString("tipo"));
p.setDescrzione(rs.getString("descrizione"));
%>
<option value="a1"> <%=p.tipo%> - <%=p.descrizione%> </option>
<%
}
}catch (SQLException sqle) {
throw new SQLException("Errore persistenza" +sqle);
}finally {
if(conn != null)
rs.close();
st.close();
conn.close();
}
%>
</td>
</tr>
</select>
</table>
<input type="submit" value="view"/>
</fieldset>
</form>
<%
String prodotto = request.getParameter( "prodotto" );
%>
nella pagina successiva ho provato a scrivere cosė..
<%
String prodotto =(String)request.getAttribute( "prodotto");
// String prodotto = (String)request.getAttribute("prodotto");
out.println("<p>"+prodotto+"</p>");
%>
mi stampa null Dove sbaglio??????
Grazie in anticipo!!!