一段很简单代码的疑问

这是截取一本书里的一个demo项目的action代码:
//封装货物基本信息
public Goods getGoodsBean(HttpServletRequest req, HttpServletResponse res) {
Goods goods = new Goods();
try {
//判断是否是新增或者修改还是删除,如果是新增则不需要id
String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
if (!"".equals(hh) && hh != null) {
goods.setId(Integer.valueOf(req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")));
}
//设定货物名
goods.setName(((String)req.getParameter("name" + (String)req.getParameter("checkbox") + "")));
//设定货物价格
goods.setPrice(Double.parseDouble(((String)req.getParameter("price" + (String)req.getParameter("checkbox") + ""))));
//设定货物数量
goods.setCount(Integer.parseInt(((String)req.getParameter("count" + (String)req.getParameter("checkbox") + ""))));
//设定货物发布日期
goods.setReleaseDate(getCurrentDate());
} catch (Exception ex) {
ex.printStackTrace();
}
return goods;
}
请问:
String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
"goodsId"是字段吗? String)req.getParameter("checkbox") 这是提取("checkbox")里的值吗?
这句怎么理解呢?

[quote]hh=req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社[/quote]
这本书我没看过,但是
(String)req.getParameter("checkbox") 返回的是xxx 这句取得是一个name属性为checkbox的元素,而不是checkbox复选款的值,因为checkbox是复选款,所有可能会有几个这样的东西,要取checkbox复选框的值,那么后台应该这样写:req.getParameters("a");返回的是一个数组,数组就是复选框各个选项的值;
"goodsId" + (String)req.getParameter("checkbox") + "",是字符串相加,""是空字符,而不是空格,提取的jsp中 goodsIdxxx的值

req.getParameter("checkbox") 中checkbox是一个参数,是jsp页面中一个name名为checkbox的元素,req.getParameter("checkbox")是取得name为checkbox的元素的值
req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
中goodsId是一个字符串而已,这个字符串+req.getParameter("checkbox")返回的值组成一个新的字符串,这个新的字符串跟checkbox一样,也是jsp页面中一个name为这个新字符串的元素,hh就是这个元素的值

String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
其中:"goodsId"是jsp页面上一个集合的名字

(String)req.getParameter("checkbox") 是提取("checkbox")里的值

其实我个人觉得这个程序应该改成如下:
//封装货物基本信息
public Goods getGoodsBean(HttpServletRequest req, HttpServletResponse res) {
Goods goods = new Goods();
try {
//得到选定的货物的下标
String check = (String)req.getParameter("checkbox");
//判断是否是新增或者修改还是删除,如果是新增则不需要id
String hh = req.getParameter("goodsId"+check);
if (!"".equals(hh) && hh != null) {
goods.setId(Integer.valueOf(req.getParameter("goodsId"+check)));
}
//设定货物名
goods.setName(((String)req.getParameter("name"+check)));
//设定货物价格
goods.setPrice(Double.parseDouble((String)req.getParameter("price"+check)));

//设定货物数量
goods.setCount(Integer.parseInt(((String)req.getParameter("count"+check)));
//设定货物发布日期
goods.setReleaseDate(getCurrentDate());
} catch (Exception ex) {
ex.printStackTrace();
}
return goods;
}
希望可以帮到你。

这样提取是错的,因为你提取的复选框,提取出来应该是个数组,应该用这个方法request.getParameterValues("name"),你那个方法只能得到一个值

quotereq.getParameter("checkbox") [/quote]
这个取的是页面中类似这样的元素的值;当然也可是type是其他的元素的值,当然也可以是复选框本身name属性值就是checkbox:,但是应该这样取::req.getParameters("checkbox");