-
회원가입, 로그인, 게시판 백엔드 실습( login 기능 구현 )Spring 2023. 4. 4. 15:49
Login 기능 구현하기
: 회원가입 기능을 이용해서, 데이터베이스에 유저 정보를 저장할 수 있게 만들었다.
이제는 유저가 로그인하기 위해 입력하는 데이터가 회원 데이터베이스 내부에 존재하는지 확인하고
데이터가 내부에 존재한다면 session에 login 기록을 저장하고
존재하지 않는다면, login 화면에 머무르게 만들 것이다.
1 . Login.jsp 구성하기
- logind은 post 방식으로 id와 password에 대한 정보를 받을 것이다.
input 태그 내부에 required="" 는 해당 칸이 비었을 경우 submit 기능을 막아주는 것이 원래의 기능이지만,
여기서는 css가 정상적으로 작동하려면 해당 attribute가 꼭 필요하다.
2. Contoller 작성
- Login.jsp의 form 태그에서 받은 id와 pass워드를 LoginVO 객체에 담아서 옮길 것이다.
또한, 매개변수로 HttpSession을 추가했는데, 이는 로그인에 성공할 경우, session에 해당 Id를 저장해서
로그아웃을 하거나, 브라우저를 닫기 전까지 저장될 것이고
이를 활용해서 유저는 로그인 했을 때만 이용할 수 있는 기능들을 이용할 수 있을 것이다.
- ls.login() 함수를 member 변수로 선언했다. 이 변수는 return 값을 가질 것이며 만일 return값이 존재하지 않는
null인 경우, login 화면으로 다시 돌아갈 것이고
null이 아니라면 return한 오브젝트에서 .getId() 함수를 실행하여 id 값을 session에 login 변수에 저장한다.
3. Server , ServerImpl 작성
- controller와 service 구간을 연결했다.
public LoginVO login() 으로 선언함으로서 해당 함수는 LoginVO 객체에 값을 담아서 리턴할 것이다.
4. Mapper, MapperImpl 작성하기
- select 문에 where을 설정하므로서, id 와 password가 데이터베이스에 동일한 데이터가 있다면
LoginVO 객체 타입으로 값을 반환한다.
5. 로그인 기능 실행하기
'Spring' 카테고리의 다른 글
회원가입, 로그인, 게시판 백엔드 실습( 게시판 글쓰기 ) (0) 2023.04.05 회원가입, 로그인, 게시판 백엔드 실습( 게시판 리스트 ) (0) 2023.04.05 회원가입, 로그인, 게시판 백엔드 실습( login 화면 ) (0) 2023.04.04 회원가입, 로그인, 게시판 백엔드 실습( main 화면 ) (0) 2023.03.31 RedirectAttribute (0) 2023.03.30