从jsp我需要在用户点击提交表单的搜索按钮时传输下拉列表中选择的值。
<form:form modelAttribute="firstVO" method="post">
<form:select path="secondVO.status"
id="status" >
<form : option value="all" label="All" />
<form : option value="new" label="New" />
</form:select>
<input type="button" name="search" value="Search" onclick="filterData();" />
</form:form>
function filterData(){
document.forms[0].action = Path+"/filter.do";
document.forms[0].submit();
}
-------------------------------------------------
public class FirstVO {
private SecondVO secondVO;
}
public class SecondVO {
private String status;
}
public class DPSController {
@RequestMapping(value = "/filter.do")
public ModelAndView filterDashboard(HttpServletRequest request, @ModelAttribute SecondVO secondVO) {
System.out.println("secondVO.getStatus:"+secondVO.getStatus());
}
}
注意:DPSController是打印状态选定值的动作类。
Any idea please?
答案 0 :(得分:0)
您的Model属性是firstVO而不是secondVO。如下所示更改filterDashboard签名应该有效。
更改
@RequestMapping(value = "/filter.do")
public ModelAndView filterDashboard(HttpServletRequest request, @ModelAttribute SecondVO secondVO) {
System.out.println("secondVO.getStatus:"+secondVO.getStatus());
}
到
@RequestMapping(value = "/filter.do")
public ModelAndView filterDashboard(HttpServletRequest request, @ModelAttribute FirstVO firstVO) {
System.out.println("firstVO.getSecondVO().getStatus:"+firstVO.getSecondVO().getStatus());
}