简体   繁体   中英

Sending multiple parameter values from a JSP to a servlet

The answer to my question is partially here but, not working for me Sending multiple parameters to servlets from either JSP or HTML

My JSP is the following

<table cellpadding = "10" border = "1">
<tr valign = "bottom">
<th align = "left" > Catalog No </th>
<th align = "left" > Chemical Name </th>
<th align = "left" > Unit </th>
<th align = "left" > Price </th>
<th align = "left" > Vendor </th>
<th align = "left" > Category </th>
<th align = "left" > Account No</th>
</tr>

<%
try
{
ArrayList<CartProduct> cp3 = (ArrayList<CartProduct>) session.getAttribute("cp");
for(CartProduct pp: cp3)
{
%>
<tr>
<td><%=pp.getCatNo()%></td>
<td><%=pp.getChemName()%></td>
<td><%=pp.getChemUnit()%></td>
<td><%=pp.getPrice()%></td>
<td><%=pp.getVendor()%></td>
<td><%=pp.getCategory()%></td>
<td><select name = "accno"><option value="--Select--">--Select--</option>
<%ArrayList<String> str=pp.getAccList();
for(String s:str)
{
%> <option value="<%=s%>"><%=s%></option>
<%  
 }
%>
</select></td><td>
<a href="DisplayCartServlet?catNo=<%=pp.getCatNo()%>&;accountNo=accno">Add To Cart
</a></td>
</tr>
<%
}
}
finally{
}
%>
</table>

How do I send the value of the list box to the servlet? Currently only catNo is being passed, but accountNo is null at the servlet.

it should be accno , it seems you are trying to retrieve param by accountNo

Also See

The easiest way to accomplish what you are attempting is to post using a form.

<form method="post" action="DisplayCartServlet">
<input type="hidden" name="catNo" value="<%=pp.getCatNo()%>">
<select name = "accno"><option value="--Select--">--Select--</option>
<%ArrayList<String> str=pp.getAccList();
for(String s:str)
{
%> <option value="<%=s%>"><%=s%></option>
<%  
 }
%>
</select>
<input type="submit" value="Add To Cart">
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM