springmvc中复选框传值

qq_38189352 2017-04-28 12:30:00
我通过

<c:forEach var="yonghuinfo1" items="${yonghuinfo1 }">
<li><a>
<tr>
<td height="44"><input type="checkbox" name="yonghuid1" value=${yonghuinfo1.id } width="150" /><!-- 姓名: -->${yonghuinfo1.name }</td>
<td ><!-- 性别: -->${yonghuinfo1.sex }</td>
<td><!-- 年龄: -->${yonghuinfo1.age }</td>
<td><!-- 手机号码: -->${yonghuinfo1.phonenum }</td>
<td><!-- 身份证: -->${yonghuinfo1.sfz }</td>
<td width="300">
<form action="${pageContext.request.contextPath}/manager/lishixx.html?yonghuinfoid=${yonghuinfo1.id}" method="post">
<input type="hidden" name="yonghuinfoid" value=${yonghuinfo.id } width="150" />
<input type="submit" value="历史记录" width="200" />
</form>
<form action="${pageContext.request.contextPath}/manager/delete_yonghuinfo.html" method="post">
<input type="hidden" name="yonghuinfoid" value=${yonghuinfo1.id } width="150" />
<input type="submit" value="删除" width="200"/>
</form>
</td>
</tr>
</a></li>
</c:forEach>
</table>
</ul>
来显示查询的结果,每个结果前都有复选框
怎么把复选框中的值通过表单传送到后台,来获取
我通过
@RequestMapping(value = "/kaihu", method = RequestMethod.POST)
public ModelAndView kaihu(@RequestParam int managerid,@RequestParam String yonghuid,HttpServletResponse response,HttpSession session)
来获取传送值
...全文
344 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_38189352 2017-04-29
  • 打赏
  • 举报
回复
谢谢大家了,主要问题实际上是我不知道吧那个form放在那个位置,现在我搞定
cgs1999 2017-04-28
  • 打赏
  • 举报
回复
下面代码中,url和post的内容为都是yonghuinfoid(历史记录中的${yonghuinfo.id }疑似写错了)

<form action="${pageContext.request.contextPath}/manager/lishixx.html?yonghuinfoid=${yonghuinfo1.id}" method="post">
<input type="hidden" name="yonghuinfoid" value=${yonghuinfo.id } width="150" />
<input type="submit" value="历史记录" width="200" />
</form>
<form action="${pageContext.request.contextPath}/manager/delete_yonghuinfo.html" method="post">
<input type="hidden" name="yonghuinfoid" value=${yonghuinfo1.id } width="150" />
<input type="submit" value="删除"  width="200"/>
</form>
而下列controller代码中,使用的参数为@RequestParam int managerid,@RequestParam String yonghuid,变量名称和post参数不一致

@RequestMapping(value = "/kaihu", method = RequestMethod.POST)
public ModelAndView kaihu(@RequestParam int managerid,@RequestParam String yonghuid,HttpServletResponse response,HttpSession session)
...
解决方法 1、调整为一致的参数名称(如变量名称yonghuid修改为yonghuinfoid,注解@RequestParam可省略不写)

@RequestMapping(value = "/kaihu", method = RequestMethod.POST)
public ModelAndView kaihu(@RequestParam int managerid,String yonghuinfoid,HttpServletResponse response,HttpSession session)
...
2、注解增加参数名称对应(@RequestParam(value="yonghuinfoid")

@RequestMapping(value = "/kaihu", method = RequestMethod.POST)
public ModelAndView kaihu(@RequestParam int managerid,@RequestParam(value="yonghuinfoid") String yonghuid,HttpServletResponse response,HttpSession session)
...
Finley-Ning 2017-04-28
  • 打赏
  • 举报
回复
复选框通常是通过前台js去定义数组或者是字符串 传到后台的吧。。 然后后台接受通过一定规则获得数组形式。比如前台可以传ids =‘1,3,5,6,8,10’ 后台一般通过字符串处理获得数组[1,3,5,6,8,10]来处理吧。 应该还有另外的方法。 我们一般都是这个做的
_jant 2017-04-28
  • 打赏
  • 举报
回复
string names[] = request.getParameterValues(String name);
Scaarf 2017-04-28
  • 打赏
  • 举报
回复
下次发代码的时候用代码片发,就是上面工具栏里有尖括号的那个图标这样看着真头晕。。。。

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧