π»
JSP νλ‘κ·Έλλ° - [MVC/DBμ°λ] λ‘κ·ΈμΈ νμ΄μ§ (λ‘κ·Έμμ, νμμμ , νμνν΄ κΈ°λ₯) (2) λ³Έλ¬Έ
KITRI/JSP
JSP νλ‘κ·Έλλ° - [MVC/DBμ°λ] λ‘κ·ΈμΈ νμ΄μ§ (λ‘κ·Έμμ, νμμμ , νμνν΄ κΈ°λ₯) (2)
λν¨λ 2020. 7. 3. 14:05[μ΄μ κΈ]
λ‘κ·ΈμΈ νμ΄μ§
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");
}
λ‘κ·ΈμΈ ν κ²°κ³Όμ°½
λ‘κ·Έμμ νμ΄μ§
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'μΈ κ΄λ¦¬μκ³μ μ΄ μμ λμλ€.
λ°μν
'KITRI > JSP' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Comments