0

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.

Community
  • 1
  • 1
Raghu
  • 1,141
  • 5
  • 20
  • 39

2 Answers2

0

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

Also See

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • i tried, but its still null, can you pls paste a sample code. My servlet code is String accno = request.getParameter("accno"); – Raghu Aug 16 '11 at 12:13
  • I assume following things, 1. you have taken a `form` 2. you are making GET or POST and appropriately reading it on the servlet – jmj Aug 16 '11 at 12:14
  • If you see my JSP code, 10 lines before ending, it has a – Raghu Aug 16 '11 at 12:18
  • This is not the way, you are making user to fill the form you need to take a `form` and `POST` it to some servlet. passing param with `GET` for specially addToCart is bad practice – jmj Aug 16 '11 at 12:20
0

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>
pap
  • 27,064
  • 6
  • 41
  • 46