MVC_Spring - ID 또는 Password 체크 하기
프로그래밍 정리/Spring
2020. 1. 2. 10:00
반응형
MVC_Spring - ID 또는 Password 체크 하기
-Redirect를 이용한 ID값 검사하기
- ID값과 함께 요청이 들어온다.
- IF문을 이용하여 분기점을 만든다.
- 만약 ID값이 알맞다면 success 페이지로 이동
- 만약 ID값이 틀리다면 fail 페이지로 이동
-실습 예제
-controller
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @RequestMapping("/studentConfirm") //studentConfirm 으로 요청이 들어온다면 public String studentRedirect(HttpServletRequest httpServletRequest, Model model){ String id = httpServletRequest.getParameter("id"); //값이 들어오면 id값을 String 으로 초기화 if(id.equals("abc")) { return "redirect:studentOk"; //id값이 abc와 같다면 OK페이지로 이동 } return "redirect:studentNg"; //id값이 abc와 같다면 Ng페이지로 이동 } @RequestMapping("/studentOk") public String studentOk(Model model){ return "student/studentOk"; } @RequestMapping("/studentNg") public String studentNg(Model model){ return "student/studentNg"; } | cs |
-studentOk
1 2 3 4 5 6 7 8 9 | <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> studentOk.jsp </body> </html> | cs |
-studentNg
1 2 3 4 5 6 7 8 9 | <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>Insert title here</title> </head> <body> studentNg.jsp </body> </html> | cs |
-결과
-id값 없을경우
-id값 맞을때
-id값 틀릴때
반응형
'프로그래밍 정리 > Spring' 카테고리의 다른 글
MVC_Spring - JDBC 템플릿 사용하기 (0) | 2020.01.02 |
---|---|
MVC_Spring - 폼 데이터 값 검증 (0) | 2020.01.02 |
MVC_Spring - Redirect 사용하기 (0) | 2019.12.31 |
MVC_Spring - @ModelAttribute 사용하기 (0) | 2019.12.31 |
MVC_Spring - @RequestParam 사용하기 (0) | 2019.12.31 |