简体   繁体   English

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

[英]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我的 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>

How do I send the value of the list box to the servlet?如何将列表框的值发送到 servlet? Currently only catNo is being passed, but accountNo is null at the servlet.目前只有 catNo 被传递,但在 servlet 中 accountNo 是 null。

it should be accno , it seems you are trying to retrieve param by accountNo应该是accno ,看来您正在尝试通过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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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