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

最后发布: 2015-07-22 21:02:53


问题

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

我有一个注册表格,用户在其中填写个人详细信息,然后单击下一步按钮,然后显示另一个注册页面以进行资格认证..i我正在使用模型属性和spring形式标签来保存用户对话状态或填充pojos ...但我正面临在第二种方法“资格模式”中绑定jsp页面中的模型属性时出现问题,我们得到了填充的候选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";
        }
spring
回答

我想你想要这个:

@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>