如何使用模型属性和spring form标签在jsp页面中绑定空pojo

时间:2015-07-22 21:02:54

标签: spring

如果有人知道春天,请帮助我:

我有一个注册表单,用户填写个人详细信息,然后点击下一步按钮 然后显示另一个注册页面进行鉴定..我正在使用模型属性和弹簧形式标签来保存用户会话状态或填充pojos ...但我在第二种方法中遇到了在jsp页面中绑定模型属性的问题&#34 ;资格模式"我们得到填充的候选人pojo,我试图在RegQualification页面中绑定空资格,但这不起作用..下面是控制器.......

    @Controller
    @RequestMapping("/register")
    public class RegisterController {

          //Displaying reg page
        @RequestMapping("/regCandidate")
        public String regCandidate(Candidate can)
        {
            return "RegCandidate";
        }


         //saving candidate and displaying reg qualification page
        @RequestMapping(value="/qualification" , method=RequestMethod.POST)
        public String regCandidate(Candidate can, HttpSession hs, Qualification q)
        {
            hs.setAttribute("candidate_personal", can);
            return "RegQualification";
        }

    //saving qualification and displaying reg project page
        @RequestMapping(value="/project" , method=RequestMethod.POST)
        public String regQualification(Qualification q,HttpSession hs,Project p)
        {
            hs.setAttribute("candidate_qualification", q);
            return "RegProject";
        }

1 个答案:

答案 0 :(得分:0)

我想你想要这个:

@RequestMapping(value="/qualification" , method=RequestMethod.POST)
    public ModelAndView regCandidate(Candidate can, HttpSession hs, Qualification q)
    {
        return new ModelAndView("RegQualification","candidate_personal",can);
    }

然后在RegQualification.jsp中你可以访问该对象' can'像这样:

<p> Candidate's name is ${candidate_personal.name} </p>