0

当用户单击提交表单的搜索按钮时,我需要从 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? 
4

1 回答 1

0

您的模型属性是 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()); 
    } 
于 2013-04-09T06:57:16.410 回答