我目前有一个显示一些棒球卡及其值的servlet。我希望能够在复选框中列出它们并能够选择想要出售的卡片。然后servlet会取出您检查的卡片并将这些值加起来并显示总数。我已经完成了大部分工作,除非我不能从复选框中获取值并总结出来。从复选框获取和添加值
这是我的jsp
<form name="CashOut.jsp" method="post">
<table>
<c:forEach var="entry" items="${winingCards}">
<tr>
<td>
<input type="checkbox" name="cardvalue" value="${entry.price}"><h1>PRICE<h1>${entry.price}$</h1><br><img src="photofolio/images/cardimages/clevelandindians/${entry.name}.png" align="middle" style="max-height:25%; max-width:25% "/>
</td>
</tr>
</c:forEach>
</table>
<table>
<tr>
<td>
<input type="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
这个错误我控制器
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
JFrame parent = new JFrame();
int sumTotal = 0;
String[] items =request.getParameterValues("cardvalue");
for(String item : items){
sumTotal=+sumTotal;
}
JOptionPane.showMessageDialog(parent, "You Cashed Out with: "+sumTotal);
request.getRequestDispatcher("/WEB-INF/photofolio/index.html").forward(
request, response);
}
}
请告诉我您的问题?这个'items'包含'null'吗? – Satya
我不知道如何从jsp获得价格值,所以我可以将它们相加。 –
用这个'request.getParameterValues(“cardvalue”)''你会得到所有的值。 – Satya