노르디아
NORDIA
노르디아
전체 방문자
오늘
어제
  • Recode (35)
    • Language (0)
      • Java (0)
    • Spring (2)
    • DBMS (16)
      • DataBase (5)
      • SQL (10)
      • MySQL (0)
      • MariaDB (1)
    • Server (0)
    • IDE (0)
      • Eclipse (0)
    • WEB (1)
    • ETC (4)
    • 게시판 만들기 (10)
      • JSP ➜ Spring (10)
      • Spring ✚ Ajax (0)
    • nordia (0)
    • Diablo4 (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • java install
  • java
  • 자바 설치
  • eclipse
  • spring
  • MariaDB
  • 자바 환경변수
  • 톰켓
  • 이클립스 설치
  • JAVA_HOME
  • 마리아디비
  • tomcat
  • 자바
  • 이클립스
  • 톰켓 설치
  • web

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
노르디아

NORDIA

[Spring] 로그인/로그아웃 구현
게시판 만들기/JSP ➜ Spring

[Spring] 로그인/로그아웃 구현

2022. 12. 19. 09:00

1. JSP 로그인 페이지

 

1
2
3
4
5
6
7
8
9
10
11
<form method="post" action="loginAct">
    <h3 style="">로그인 화면</h3>
    <div class="from-group">
        <input type="text" class="form-control" placeholder="아이디"
            name="userID" maxlength="20">
    </div>
    <input type="password" class="form-control" placeholder="비밀번호"
        name="userPassword" maxlength="20">
    </div>
    <input type="submit" class="btn btn-primary form-control" value="로그인">
</form>
cs

 

2. 로그인 Controller

로그인하는 사용자의 아디와 비밀번호를 받아와서 비교 후 해당 유저가 있으면 Session에 key, value 형태로
저장하여 메인 페이지로 이동하고 사용자 정보가 잘못되거나 없으면 로그인 페이지를 새로고침
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//로그인
@RequestMapping(value = "/loginAct", method = RequestMethod.POST)
public String loginAct(HttpServletRequest request, HttpServletResponse response,
        HttpSession session,
        @RequestParam String userID,
        @RequestParam String userPassword) {
    
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("userID", userID);
    map.put("userPassword", userPassword);
    MemberDTO member = memberSvc.selectMemberLogin(map);
    
    if (member != null) {
        session.setAttribute("userID", userID);
        return "redirect:/main";
    }else {
        return "redirect:/login";
    }
}
cs

 

3. 로그인 Service

1
2
3
4
//로그인
public MemberDTO selectMemberLogin(Map<String, Object> map) {
    return session.selectOne("selectMemberLogin", map);
}
cs

 

4. 로그인 Select 쿼리

1
2
3
4
5
<!-- 로그인 -->
<select id="selectMemberLogin" parameterType="java.util.Map" resultType="com.member.MemberDTO">
    SELECT * FROM bbs.user
    WHERE userID = #{userID} AND userPassword = #{userPassword}
</select>
cs

 

5. 로그아웃 Controller

로그아웃하면 Session을 비워주고 메인페이지를 새로고침
1
2
3
4
5
6
7
//로그아웃
@RequestMapping(value = "/logoutAct", method = RequestMethod.GET)
public String logoutAct(HttpServletRequest request, HttpServletResponse response,
        HttpSession session) {    
    session.invalidate();
    return "redirect:/main";
}
cs

 

'게시판 만들기 > JSP ➜ Spring' 카테고리의 다른 글

[Spring] 게시판 구현 페이징 처리  (0) 2022.12.24
[Spring] 메인 페이지/내비게이션 <jsp:include>  (0) 2022.12.20
[Spring] 회원 가입 구현  (0) 2022.12.18
[Side Project] 게시판  (0) 2022.12.18
[Spring] 1.회원가입/로그인 구현  (0) 2022.12.17
    '게시판 만들기/JSP ➜ Spring' 카테고리의 다른 글
    • [Spring] 게시판 구현 페이징 처리
    • [Spring] 메인 페이지/내비게이션 <jsp:include>
    • [Spring] 회원 가입 구현
    • [Side Project] 게시판
    노르디아
    노르디아
    IT 개발을 배우고 있는 NORDIA 입니다

    티스토리툴바