rael_gc 26 de abr. de 2011
Acredito que o mais correto seria:
<form name= "formcarrinho" method= "post" action= "" >
Roupa: <input name= "items[]" value= "roupa" type= "checkbox" /><br>
Comida: <input name= "items[]" value= "comida" type= "checkbox" /><br>
<input name= "comprar" type= "submit" />
</form>
lazaropj 26 de abr. de 2011
Coloca um value na sua tag input e pega ela lá na servlet com um request.getParameter();
felipevs 26 de abr. de 2011
aqui eu passo o que como parametro ?
items[] ou o value ?
roupa = String.valueOf(request.getParameter(“comida”));
felipevs 26 de abr. de 2011
Onde está o erro ?
<form name= "formcarrinho" method= "post" action= "" >
Roupa: <input name= "item[]" type= "checkbox" value= "roupa" /><br>
Comida: <input name= "item[]" type= "checkbox" value= "comida" /><br>
<input name= "comprar" type= "submit" />
</form>
</center>
<%
String comprar = "" ;
String roupa = "" ;
String comida = "" ;
comprar = String . valueOf ( request . getParameter ( "comprar" ));
if ( comprar . equalsIgnoreCase ( "comprar" )) {
roupa = String . valueOf ( request . getParameter ( "roupa" )); // <-----------
comida = String . valueOf ( request . getParameter ( "comida" )); //<----------
}
out . println ( roupa );
out . println ( comida );
%>
felipevs 26 de abr. de 2011
lazaropj 26 de abr. de 2011
felipevs:
Onde está o erro ?
<form name= "formcarrinho" method= "post" action= "" >
Roupa: <input name= "item[]" type= "checkbox" value= "roupa" /><br>
Comida: <input name= "item[]" type= "checkbox" value= "comida" /><br>
<input name= "comprar" type= "submit" />
</form>
</center>
<%
String comprar = "" ;
String roupa = "" ;
String comida = "" ;
comprar = String . valueOf ( request . getParameter ( "comprar" ));
if ( comprar . equalsIgnoreCase ( "comprar" )) {
roupa = String . valueOf ( request . getParameter ( "roupa" )); // <-----------
comida = String . valueOf ( request . getParameter ( "comida" )); //<----------
}
out . println ( roupa );
out . println ( comida );
%>
o seu input:
< input name = "comprar" type = "submit" / >
Não tem um value… então ele não entra no if:
if ( comprar .equalsIgnoreCase ( "comprar" )) {
lazaropj 26 de abr. de 2011
E meu amigo… Use Servlet para fazer isso aí. Acho q ficaria melhor.