https://github.com/kai8406/cmop/commit/b40d745fc0f5a902d1af17955d8be47a0230e28d#diff-0
-package com.sobey.mvc.web; | ||
| 2 |
- | |
| 3 |
-import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; | |
| 4 |
-import org.springframework.stereotype.Controller; | |
| 5 |
-import org.springframework.ui.Model; | |
| 6 |
-import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 |
-import org.springframework.web.bind.annotation.RequestMethod; | |
| 8 |
-import org.springframework.web.bind.annotation.RequestParam; | |
| 9 |
- | |
| 10 |
-/** | |
| 11 |
- * LoginController负责打开登录页面(GET请求)和登录出错页面(POST请求), | |
| 12 |
- | |
| 13 |
- * 真正登录的POST请求由Filter完成, | |
| 14 |
- * | |
| 15 |
- * @author calvin | |
| 16 |
- */ | |
| 17 |
-@Controller | |
| 18 |
-public class LoginController {
| |
| 19 |
- | |
| 20 |
- @RequestMapping(value = "/login", method = RequestMethod.GET) | |
| 21 |
- public String login() {
| |
| 22 |
- return "login"; | |
| 23 |
- } | |
| 24 |
- | |
| 25 |
- @RequestMapping(value = "/login", method = RequestMethod.POST) | |
| 26 |
- public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName, Model model) {
| |
| 27 |
- model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, userName); | |
| 28 |
- return "login"; | |
| 29 |
- } | |
| 30 |
- | |
| 31 |
-} | |
| 1 |
+package com.sobey.mvc.web; | |
| 2 |
+ | |
| 3 |
+import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; | |
| 4 |
+import org.springframework.stereotype.Controller; | |
| 5 |
+import org.springframework.ui.Model; | |
| 6 |
+import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 |
+import org.springframework.web.bind.annotation.RequestMethod; | |
| 8 |
+import org.springframework.web.bind.annotation.RequestParam; | |
| 9 |
+ | |
| 10 |
+/** | |
| 11 |
+ * LoginController负责打开登录页面(GET请求)和登录出错页面(POST请求), | |
| 12 |
+ * | |
| 13 |
+ * 真正登录的POST请求由Filter完成, | |
| 14 |
+ * | |
| 15 |
+ */ | |
| 16 |
+@Controller | |
| 17 |
+public class LoginController {
| |
| 18 |
+ | |
| 19 |
+ @RequestMapping(value = "/login", method = RequestMethod.GET) | |
| 20 |
+ public String login() {
| |
| 21 |
+ return "login"; | |
| 22 |
+ } | |
| 23 |
+ | |
| 24 |
+ /** | |
| 25 |
+ * 成功登录进入页面,如果未成果则跳转到signUp页面重新登录. | |
| 26 |
+ */ | |
| 27 |
+ @RequestMapping(value = "/login", method = RequestMethod.POST) | |
| 28 |
+ public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName, Model model) {
| |
| 29 |
+ model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, userName); | |
| 30 |
+ return FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME != null ? "signUp" : "login"; | |
| 31 |
+ } | |
| 32 |
+ | |
| 33 |
+} |
本文详细阐述了如何通过改进的登录控制器实现登录页面的GET请求和登录错误页面的POST请求处理,包括过滤器的作用和登录流程。
565

被折叠的 条评论
为什么被折叠?



