第一种方式是 通过session
第二种如下:
如何将controller层值传递到JSP页面
@RequestMapping(value="/result",method=RequestMethod.GET)
public String test2(HttpServletRequest request,User user){
//在此请求中存储属性
//属性名称/属性值
request.setAttribute("name1", user.getUsername());
request.setAttribute("pass1", user.getPassword());
System.out.println(user.getUsername());
System.out.println(user.getPassword());
return "result";
}
result.jsp中
<body>
<h2>登陆</h2> username:${name1 } <p> password:${pass1 }</p>
</body>
第三种:
使用ModelAndView
@RequestMapping(value="/result",method=RequestMethod.GET)
public ModelAndView test2(@RequestParam("username")String user,@RequestParam("password") String pass){
ModelAndView mav = new ModelAndView();
mav.setViewName("result");
mav.addObject("name1", user);
mav.addObject("pass1",pass);
System.out.println(user );
System.out.println(pass);
return mav;
}
result.jsp中
<body>
<h2>登陆</h2> username:${name1 } <p> password:${pass1 }</p>
</body>