将多个参数值从JSP发送到servlet

时间:2011-08-16 11:59:56

标签: html jsp servlets html-form

我的问题的答案部分在这里,但不适合我 Sending multiple parameters to servlets from either JSP or HTML

我的JSP是以下

<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>

如何将列表框的值发送到servlet?目前只传递catNo,但servlet上的accountNo为空。

2 个答案:

答案 0 :(得分:0)

它应该是accno,您似乎试图通过accountNo

检索参数

另见

答案 1 :(得分:0)

完成您尝试的内容的最简单方法是使用表单发布。

<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>