Issue
I am trying to send a value to my servlet with two inputs, one that is going to have my product name(type hidden) and the other to submit that value;
for(Product product : listProducts)
{
out.print("Name: " + product.getName());
%>
<input type="hidden" name="flag" value="<% out.println(product.getName()); %>">
<input type="submit" value="Add to cart"/>
<br>
<%
}
The problem is that I only get the first value of the products. And if I do this:
for(Product product : listProducts)
{
out.print("Name: " + product.getName());
%>
<input type="submit" name="flag" value="<% out.println(product.getName()); %>">
<br>
<%
}
it works just fine. So I think is something with the hidden input.
Solution
Try surrounding both <input>
s with a <form></form>
.
Answered By - admdev