JSP - Maven - Member (Login/Log out)

화이티 ·2023년 12월 21일
0

JSP

목록 보기
5/12

Login - logout member 💫💙

<!-- Q3. 로그인 기능 만들기 -->
			<li><h5>로그인</h5></li>
			<form action="LoginService" method="post">
				<li><input type="text" placeholder="Email을 입력하세요" name="email"></li>

				<li><input type="password" placeholder="PW를 입력하세요" name="pw"></li>
				<li><input type="submit" value="LogIn" class="button fit"></li>
			</form>
		</ul>
		<ul class="actions vertical">

Member 변수 declaration

package com.smhrd.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
@Getter
@NoArgsConstructor
@ToString
@RequiredArgsConstructor
@AllArgsConstructor
public class Member {

	@NonNull
	private String email;
	@NonNull
	private String pw;
	
	private String tel;
	private String address;
	
}

MemberDAO

public Member loginMember(Member vo) {
		Member loginMember = null;
		
		try {
			loginMember = sqlSession.selectOne("com.smhrd.database.MemberMapper.loginMember",vo);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		return loginMember;

Login Service

request.setCharacterEncoding("UTF-8");
		String email = request.getParameter("email");
		String pw = request.getParameter("pw");

		Member vo = new Member(email, pw);
		Member loginMember = new MemberDAO().loginMember(vo);

		if (loginMember != null) {
			HttpSession session = request.getSession();
			session.setAttribute("loginMember", loginMember);
			System.out.println("성공");

		}
		response.sendRedirect("Main.jsp");

Log out service

HttpSession session = request.getSession();
		session.removeAttribute("loginMember");
		response.sendRedirect("Main.jsp");
	}
}

Member Mapper

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<select id ="loginMember" parameterType = "Member" resultType ="Member" >
select * from WEB_MEMBER where email =#{email} and pw =#{pw} 
</select>

My batis - config

<typeAlias type="com.smhrd.model.Member" alias ="Member"/>
<mapper resource="com/smhrd/database/MemberMapper.xml"/>

After login successfully , show information detail

profile
열심히 공부합시다! The best is yet to come! 💜

0개의 댓글