πŸ’»

JSP ν”„λ‘œκ·Έλž˜λ° - [MVC/DB연동] 둜그인 νŽ˜μ΄μ§€ (λ‘œκ·Έμ•„μ›ƒ, νšŒμ›μˆ˜μ •, νšŒμ›νƒˆν‡΄ κΈ°λŠ₯) (2) λ³Έλ¬Έ

KITRI/JSP

JSP ν”„λ‘œκ·Έλž˜λ° - [MVC/DB연동] 둜그인 νŽ˜μ΄μ§€ (λ‘œκ·Έμ•„μ›ƒ, νšŒμ›μˆ˜μ •, νšŒμ›νƒˆν‡΄ κΈ°λŠ₯) (2)

λ˜νš¨λ‹ˆ 2020. 7. 3. 14:05

[이전글]

2020/07/01 - [KITRI/JSP] - JSP ν”„λ‘œκ·Έλž˜λ° - [MVC/DB연동] νšŒμ›κ°€μž… νŽ˜μ΄μ§€ (아이디쀑볡체크, μš°νŽΈλ²ˆν˜Έκ²€μƒ‰ κΈ°λŠ₯, μœ νš¨μ„±κ²€μ‚¬) (1)

 

JSP ν”„λ‘œκ·Έλž˜λ° - [MVC/DB연동] νšŒμ›κ°€μž… νŽ˜μ΄μ§€ (아이디쀑볡체크, μš°νŽΈλ²ˆν˜Έκ²€μƒ‰ κΈ°λŠ₯, μœ νš¨μ„±κ²€μ‚¬)

- DBμ—°κ²° μ‹œ 데이터λ₯Ό μ²˜λ¦¬ν•  μƒˆλ‘œμš΄ 계정을 μƒμ„±ν•œλ‹€. mvc(ID)/1234(PW) 둜 μƒˆλ‘œμš΄ 계정을 μƒμ„±ν–ˆλ‹€. 1. cmd μ—μ„œ SQL 계정 μΆ”κ°€ - Oracle SQL Developer μ—μ„œ mvc 계정에 μ ‘μ†ν•΄μ„œ member ν…Œμ΄λΈ”μ„ μƒμ„±ν•œλ‹€. n..

hyonee.tistory.com

 

둜그인 νŽ˜μ΄μ§€

 

 

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${root}/javascript/member/rutil.js"></script>
</head>
<body>
	<jsp:include page="../../../index.jsp"/>
	<br /><br />
	<div align="center">
		<form action="${root}/member/loginOk.do" method="post" onsubmit="return idCheckFun(this)">
			<table>
				<tr>
					<td>νšŒμ› ID</td>
					<td>
						<input type="text" name="id"/>
					</td>
				</tr>
				<tr>
					<td>λΉ„λ°€λ²ˆν˜Έ</td>
					<td>
						<input type="password" name="password"/>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<input type="submit" name="확인"/>
						<input type="reset" name="μ·¨μ†Œ"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

 

LoginOk.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri = "http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<c:if test="${memberLevel!=null}">
		<c:set var= "id" value="${id}" scope="session"/>
		<c:set var= "memberLevel" value="${memberLevel}" scope="session"/>
		
		<script type="text/javascript">
			alert("둜그인 성곡");
			location.href = "${root}/member/main.do";
		</script>
	</c:if>

	<c:if test="${memberLevel==null}">
		<script type="text/javascript">
			alert("아이디와 λΉ„λ°€λ²ˆν˜Έλ₯Ό ν™•μΈν•˜μ„Έμš”");
			location.href = "${root}/member/login.do";
		</script>
	</c:if>
</body>
</html>

 

LoginCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java.command.Command;

public class LoginCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	// TODO Auto-generated method stub
	return "/WEB-INF/views/member/login.jsp";
    }
}

 

LoginCommandOk.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java.command.Command;
import com.java.member.model.MemberDao;

public class LoginCommandOk implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

	String id = request.getParameter("id");
	String password = request.getParameter("password");
	logger.info(logMsg + id + "\t" +  password);
	
	String memberLevel = MemberDao.getInstance().loginCheck(id, password);
	logger.info(logMsg + memberLevel);
	
	request.setAttribute("memberLevel", memberLevel);
	request.setAttribute("id", id);
	
	return "/WEB-INF/views/member/loginOk.jsp";
    }
}

 

main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<jsp:include page="../../../index.jsp"/>
	<br /><br />
	<h3>μ•ˆλ…•ν•˜μ„Έμš”! ${id} λ‹˜ 즐거운 μ‹œκ°„λ˜μ„Έμš”. </h3>
</body>
</html>

 

mainCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java.command.Command;

public class mainCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	// TODO Auto-generated method stub
	return "/WEB-INF/views/member/main.jsp";
    }
}

 

rutil.js

function idCheckFun(obj){
	alert("OK");
}

 

 

둜그인 ν›„ κ²°κ³Όμ°½

둜그인 성곡 ν›„ νŽ˜μ΄μ§€(member_level=ma κ΄€λ¦¬μžμΈ 경우 κ΄€λ¦¬μž νŽ˜μ΄μ§€ 라고 화면에 좜λ ₯)


 

λ‘œκ·Έμ•„μ›ƒ νŽ˜μ΄μ§€

 

 

logout.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<c:set var="root" value="${pageContext.request.contextPath}"/>

	<c:remove var="id" scope="session"/>
	<c:remove var="memberLevel" scope="session"/>
	
	<script type="text/javascript">
		alert("λ‘œκ·Έμ•„μ›ƒ λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
		location.href = "${root}/member/login.do";
	</script>
</body>
</html>

 

LoginOutCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.java.command.Command;

public class LoginOutCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	HttpSession session = request.getSession();
	
//	if(!session.isNew()) {
//	    String id = (String) session.getAttribute("id");
//	    String memberLevel = (String) session.getAttribute("memberLevel");
//	    logger.info(logMsg + id + "\t" + memberLevel);
//	}
	
	return "/WEB-INF/views/member/logout.jsp";
    }

}

 

 


νšŒμ›μˆ˜μ • νŽ˜μ΄μ§€

 

update.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<c:set var="root" value="${pageContext.request.contextPath}" />
<html>
<head>
<meta charset="UTF-8">
<title>νšŒμ›κ°€μž…page</title>
	<link rel="stylesheet" href="${root}/css/member/joinStyle.css?ver=1">
	<script type="text/javascript" src="${root}/javascript/member/register.js"></script>
</head>
<body>
	<jsp:include page="../../../index.jsp"/>
	<br /><br />
	<form id="joinform" name="joinform" action="${root}/member/updateOk.do" method="post" 
		onsubmit="return createFrom(this)">

		<h4 style="text-align: center;">νšŒμ›κ°€μž…(*ν•„μˆ˜μž…λ ₯μ‚¬ν•­μž…λ‹ˆλ‹€.)</h4>
		<div class="menu" style="border-bottom-width: 0px;">
		
		<input type="hidden" name="num" value="${memberDto.num}"/>

		<div id="id">아이디</div>
			<span>* 
				<input type="text" class="UserInfo" name="id" size="12" value="${memberDto.id}" readonly="readonly"/> 
			</span>
		</div>

		<div class="menu " style="border-bottom-width: 0px;">
			<div id="id">λΉ„λ°€λ²ˆν˜Έ</div>
			<span>* <input type="password" class="checkInfo" name="password" size="12" value="${memberDto.password}"/>
			</span>
		</div>

		<div class="menu " style="border-bottom-width: 0px;">
			<div id="id">λΉ„λ°€λ²ˆν˜Έν™•μΈ</div>
			<span>* <input type="password" class="checkInfo" name="passwordCheck" size="12"  value="${memberDto.password}"/>
			</span>
		</div>

		<div class="menu " style="border-bottom-width: 0px;">
			<div id="id">이름</div>
			<span>* <input type="text" class="checkInfo" name="name" size="12"  value="${memberDto.name}" disabled="disabled"/>
			</span>
		</div>

		<div class="menu " style="border-bottom-width: 0px;">
			<div id="id">주민번호</div>
			<span>* 
				<input type="text" class="checkInfo" name="jumin1" size="6" value="${memberDto.jumin1}" disabled="disabled"/> 
				<span>-</span> 
				<input type="text" class="checkInfo" name="jumin2" size="7" value="${memberDto.jumin2}" disabled="disabled"/>
			</span>
		</div>

		<div class="menu" style="border-bottom-width: 0px;">
			<div id="id" style="margin-left: 10px,">이메일</div>
			<span> 
				<input type="email" name="email" size="25" value="${memberDto.email}" />
			</span>
		</div>


		<div class="menu" style="border-bottom-width: 0px;">
			<div id="id">우편번호</div>
			<span> 
				<input type="text" name="zipcode" size="30" value="${memberDto.zipcode}"/> 
				<button type="button" onclick="searchZipcode('${root}')">μš°νŽΈλ²ˆν˜Έκ²€μƒ‰</button>
			</span>
		</div>

		<div class="menu" style="border-bottom-width: 0px;">
			<div id="id">μ£Όμ†Œ</div>
			<span> <input type="text" name="address" size="50" value="${memberDto.address}" />
			</span>
		</div>

		<div class="menu" style="border-bottom-width: 0px;">
			<div id="id">직업</div>
			<span> <select name="job">
					<option>직업을 μ„ νƒν•˜μ„Έμš”.</option>
					<option value=' '>무직</option>
					<option value='programmer'>ν”„λ‘œκ·Έλž˜λ¨Έ</option>
					<option value='designer'>λ””μžμ΄λ„ˆ</option>
			</select>
			<%-- ${memberDto.job} --%>
			</span>
			<script type="text/javascript">
			joinform.job.value = "${memberDto.job}"
			</script>
		</div>


		<div class="menu" style="border-bottom-width: 0px;">
			<div id="id">λ©”μΌμˆ˜μ‹ </div>
			<span> <input type="radio" id="yes" name="mailing" value="yes" />
				<label for="yes">yes</label> <input type="radio" id="no"
				name="mailing" value="no" /> <label for="no">no</label>
				<%-- ${memberDto.mailing} --%>
			</span>
			<script type="text/javascript">
			for(var i = 0; i<joinform.mailing.length; i++){
				if(joinform.mailing[i].value == "${memberDto.mailing}"){
					joinform.mailing[i].checked = true;
				}
			}
			</script>
		</div>

		<div class="menu" style="border-bottom-width: 0px;">
			<div id="id">관심뢄야</div>
			<span> 
				<input type="checkbox" size="12" name="interest" value="경제"/> 
				<label for="경제" >경제</label> 
				<input type="checkbox" size="12" name="interest" value="IT"/> 
				<label for="IT" >IT</label>
				<input type="checkbox" size="12" name="interest" value="μŒμ•…"/>
				<label for="μŒμ•…" >μŒμ•…</label> 
				<input type="checkbox" size="12" name="interest" value="미술"/> 
				<label for="미술" >미술</label>
				<input type="hidden" name="resultInterest"/>
				<%-- ${memberDto.interest} --%>
			</span>	
			<c:forTokens var="interest" items="${memberDto.interest}" delims=",">
				<script type="text/javascript">
					for(var i = 0; i<joinform.interest.length; i++){
						if(joinform.interest[i].value == "${interest}"){
							joinform.interest[i].checked = true;
						}
					}
				</script>
			</c:forTokens>
		</div>
		
		<div class="menu" style="text-align: center;">
			<span> 
				<input type="submit" value="μˆ˜μ •" />
			 	<input type="reset" value="μ·¨μ†Œ" />
			</span>
		</div>
	</form>
</body>
</html>

 

updateOk.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<c:set var="root" value="${pageContext.request.contextPath}"/>
	<c:if test="${check > 0 }">
		<script type="text/javascript">
			alert("νšŒμ› μˆ˜μ • λ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
			location.href="${root}/member/main.do";
		</script>
	</c:if>
	<c:if test="${check == 0 }">
		<script type="text/javascript">
			alert("νšŒμ› μˆ˜μ • λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.");
			location.href="${root}/member/update.do";
		</script>
	</c:if>
</body>
</html>

 

updateCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.java.command.Command;
import com.java.member.model.MemberDao;
import com.java.member.model.MemberDto;

public class UpdateCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	// TODO Auto-generated method stub
	HttpSession session = request.getSession();
	String id = (String) session.getAttribute("id");
	logger.info(logMsg + id); 
	
	MemberDto memberDto = MemberDao.getInstance().updateId(id);
	logger.info(logMsg + memberDto.toString());
	
	request.setAttribute("memberDto", memberDto);
	
	return "/WEB-INF/views/member/update.jsp";
    }

}

 

updateOkCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.java.command.Command;
import com.java.member.model.MemberDao;
import com.java.member.model.MemberDto;

public class UpdateOkCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	// TODO Auto-generated method stub
	
	request.setCharacterEncoding("utf-8");
	MemberDto memberDto = new MemberDto();
	
	// idκ°€ disabled 이기 λ•Œλ¬Έμ— 값을 λ„˜κ²¨μ£Όμ§€ μ•Šμ•„ μ„Έμ…˜μ„ μ‚¬μš©ν•œλ‹€.  
	/* HttpSession session = request.getSession();
	memberDto.setId((String) session.getAttribute("id"));*/
	
	memberDto.setNum(Integer.parseInt(request.getParameter("num")));
	memberDto.setPassword(request.getParameter("password"));
	memberDto.setEmail(request.getParameter("email"));
	
	memberDto.setZipcode(request.getParameter("zipcode"));
	memberDto.setAddress(request.getParameter("address"));
	memberDto.setJob(request.getParameter("job"));
	memberDto.setMailing(request.getParameter("mailing"));
	memberDto.setInterest(request.getParameter("interest"));
	
	logger.info(logMsg + memberDto);
	
	int check = MemberDao.getInstance().update(memberDto);
	logger.info(logMsg + check);
	
	request.setAttribute("check", check);
	
	return "/WEB-INF/views/member/updateOk.jsp";
    }

}

 

 


νšŒμ›νƒˆν‡΄ νŽ˜μ΄μ§€

 

 

delete.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<jsp:include page="../../../index.jsp"/>
	
	<c:set var="root" value="${pageContext.request.contextPath}"/>
	<div align="center">
		<form action="${root}/member/deleteOk.do" method="post">
			<table>
				<tr>
					<td>νšŒμ›μ•„μ΄λ””</td>
					<td><input type="text" name="id" value="${id}" readonly="readonly"/></td>
				</tr>
				<tr>
					<td>λΉ„λ°€λ²ˆν˜Έ</td>
					<td><input type="password" name="password"/></td>
				</tr>
				<tr>
					<td colspan="2" align="center">
						<input type="submit" value="νšŒμ›νƒˆν‡΄"/>
						<input type="reset" value="μ·¨μ†Œ"/>
					</td>
				</tr>
			</table>	
		</form>
	</div>
</body>
</html>

 

deleteOk.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<c:set var="root" value="${pageContext.request.contextPath}"/>
	
	<c:choose>
		<c:when test="${check > 0}">
			<c:remove var="id" scope="session"/>
			<c:remove var="memberLevel" scope="session"/>
			
			<script type="text/javascript">
				alert("νšŒμ›νƒˆν‡΄κ°€ μ™„λ£Œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.");
				location.href = "${root}/member/register.do";
			</script>
		</c:when>
		
		<c:when test="${check == 0}">
			<script type="text/javascript">
				alert("νšŒμ›νƒˆν‡΄ λ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€.");
				location.href = "${root}/member/delete.do";
			</script>
		</c:when>
	</c:choose>
</body>
</html>

 

DeleteCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java.command.Command;

public class DeleteCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
	return "/WEB-INF/views/member/delete.jsp";
    }
}

 

DeleteOkCommand.java

package com.java.member.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java.command.Command;
import com.java.member.model.MemberDao;

public class DeleteOkCommand implements Command {

    @Override
    public String proRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
	String id = request.getParameter("id");
	String password = request.getParameter("password");
	logger.info(logMsg + id + "\t" + password);
	
	int check = MemberDao.getInstance().delete(id, password);
	logger.info(logMsg + check);
	
	request.setAttribute("check", check);
	
	return "/WEB-INF/views/member/deleteOk.jsp";
    }
}

 

νšŒμ›νƒˆν‡΄ κ²°κ³Ό μ°½

Oracle SQL Developerμ—μ„œ memberν…Œμ΄λΈ”μ˜ 데이터λ₯Ό μ‘°νšŒν•΄λ³΄λ©΄ idκ°€ 'bbb'인 κ΄€λ¦¬μžκ³„μ •μ΄ μ‚­μ œλ˜μ—ˆλ‹€.

 

 

 

 

λ°˜μ‘ν˜•
Comments