Controller的写法:
@Controller
@RequestMapping("/auth")
public class LoginLogoutController {
private static final Logger logger = LoggerFactory.getLogger(LoginLogoutController.class);
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView getLoginPage(@RequestParam(value = "error", required = false) boolean error) {
logger.debug("Received request to show login page");
String errorValue = null;
if (error == true) {
errorValue = "You have entered an invalid username or password!";
} else {
errorValue = "";
}
Map model = new HashMap();
model.put("error", errorValue);
ModelAndView mav = new ModelAndView("loginpage", model);
return mav;
}
---------------
JSp页面获取ModelAndView传递的值
pageEncoding="UTF-8"%>
LoginLogin
Username
Password
-----------------
测试:
http://localhost:8080/spring/auth/login?error=true
--------------------
http://localhost:8080/spring/auth/login