< File.txt >
파일 처리하는 form 의 메서드 및 enctype
enctype : form data 가 서버로 보내질 때 인코딩 타입
method="post" enctype="multipart/form-data"
업로드 파일이 저장되는 폴더
파일을 업로드하면서 form 을 분석하는 라이브러리
cos.jar
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>fileForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
padding: 4px;
}
textarea {
resize: none;
}
</style>
</head>
<body>
<h1>파일 업로드</h1>
<br>
<form action="fileUpload.jsp" method="post" enctype="multipart/form-data">
<table>
<tr>
<th>제목</th>
<td><input type="text" name="subject" size="50"/></td>
</tr>
<tr>
<th>내용</th>
<td><textarea rows="20" cols="52" name="content"></textarea> </td>
</tr>
<tr>
<td colspan="2">
<input type="file" name="upload" size="50"/>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="upload"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.File"%>
<%@page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
// 실제 저장되는 폴더 경로
String realFolder = request.getServletContext().getRealPath("/storage");
// 파일 업로드 객체
// - MultipartRequest( request, 저장경로, 파일크기, 인코딩 방식, 파일정책 )
// 파일크기 : 1024*1024 = 1MB
// * new DefaultFileRenamePolicy()
// : 업로드시 동일한 이름의 파일이 있을 경우, 기본 파일 이름 뒤에 숫자를 붙여서 저장
MultipartRequest mr = new MultipartRequest(request, realFolder, 1024 * 1024 * 5, "utf-8",
new DefaultFileRenamePolicy());
String subject = mr.getParameter("subject");
String content = mr.getParameter("content");
// 업로드 파일명
// fileForm 에서 input > name = upload
String originalFileName = mr.getOriginalFileName("upload");
// 서버에 저장된 파일명
String fileName = mr.getFilesystemName("upload");
// 파일 객체
File file = mr.getFile("upload");
long fileSize = 0;
if (file != null) {
fileSize = file.length();
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>fileUpload.jsp</title>
</head>
<body>
<h1>업로드 확인</h1>
<br>
<ul>
<li>제목 : <%=subject%></li>
<li>내용 : <%=content%></li>
<li>저장위치 : <%=realFolder%></li>
<li>업로드한 파일명: <%=originalFileName%></li>
<li>서버에 저장된 파일명: <a href="fileDownload.jsp?fileName=<%=URLEncoder.encode(fileName, "utf-8")%>"><%=fileName%></a></li>
</ul>
</body>
</html>
<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.File"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String fileName = request.getParameter("fileName");
// 실제 파일이 저장된 폴더 경로
String realFolder = request.getServletContext().getRealPath("/storage");
// 파일 객체 생성
File file = new File(realFolder, fileName);
// 파일 링크를 클릭했을 때 다운로드 화면 처리
fileName = "attachment;fileName=" + new String(URLEncoder.encode(fileName,"utf-8")).replaceAll("\\+", " ");
response.setHeader("Content-Disposition", fileName);
response.setHeader("Content-length", file.length()+"");
out.clear(); // out 객체의 스트림 삭제
out = pageContext.pushBody(); // 다운로드 정보 저장
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
byte[] fs = new byte[(int)file.length()];
bis.read(fs, 0, fs.length);
bos.write(fs);
bis.close();
bos.close();
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>fileDownload.jsp</title>
</head>
<body>
</body>
</html>
라이브러리에
cos.jar
ojdbc8.jar
taglibs-standard-compat-1.2.5.jar
taglibs-standard-impl-1.2.5.jar
taglibs-standard-jstlel-1.2.5.jar
taglibs-standard-spec-1.2.5.jar
tomcat-dbcp.jar
추가
/* index.css */
@charset "utf-8";
* {
margin: 0 auto;
}
h1, h2{
text-align: center;
}
header {
border:1px solid red;
width: 100%;
margin: 0;
padding: 30px;
}
main {
border: 1px solid gray;
width: 100%;
height: 700px;
margin: 0;
padding: 0;
}
main aside {
border: 1px solid orange;
float: left;
background-color: gold;
width: 15%;
height: 700px;
}
main aside nav h2 {
padding: 20px;
}
main aside nav a:link, nav a:visited, nav a:active {
color: black;
text-decoration: none;
}
main aside nav a:hover {
color: red;
text-decoration: underline;
}
main section {
border: 1px solid blue;
float: left;
width: 84%;
height: 700px;
}
footer {
border: 1px solid green;
clear: both;
width: 100%;
margin: 0;
padding: 30px;
text-align: center;
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="root" value="${pageContext.request.contextPath }" scope="application"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>index.jsp</title>
<link rel="stylesheet" type="text/css" href="${root }/css/index.css">
</head>
<body>
<header>
<h1 align="center">Index</h1>
</header>
<main>
<aside>
<nav>
<a href="${root }/main/index.jsp" id="main">main</a> <br>
<br>
<c:if test="${sessionScope.memberId == null }">
<a href="${root }/main/index.jsp?req=writeForm"> 회원가입 </a>
<br><br>
<a href="${root }/main/index.jsp?req=loginForm"> 로그인 </a>
</c:if>
<c:if test="${sessionScope.memberId != null }">
<a href="${root }/member/logout.jsp">로그아웃</a>
<br><br>
<a href="${root }/member/modifyReady.jsp"> 회원정보 수정</a>
<br><br>
<a href="${root }/main/index.jsp?req=boardWriteForm"> 글쓰기 </a>
<br><br>
<a href="${root }/main/index.jsp?req=imageboardWriteForm"> 상품 등록 </a>
<br><br>
<a href="${root }/imageboard/imageboardList.jsp?pg=1"> 상품 목록 </a>
</c:if>
<br><br>
<a href="${root }/board/boardList.jsp?pg=1"> 글목록 </a>
</nav>
</aside>
<!-- // aside end -->
<section>
<!-- main -->
<c:if test="${param.req == null }">
<jsp:include page="body.jsp"/>
</c:if>
<!-- 회원가입 -->
<c:if test="${param.req =='writeForm' }">
<jsp:include page="../member/writeForm.jsp"/>
</c:if>
<c:if test="${param.req =='writeResult' }">
<jsp:include page="../member/writeResult.jsp"/>
</c:if>
<!-- 로그인 -->
<c:if test="${param.req =='loginForm' }">
<jsp:include page="../member/loginForm.jsp"/>
</c:if>
<!-- 로그인ok -->
<c:if test="${param.req =='loginOk' }">
<jsp:include page="../member/loginOk.jsp"/>
</c:if>
<!-- 로그인fail -->
<c:if test="${param.req =='loginFail' }">
<jsp:include page="../member/loginFail.jsp"/>
</c:if>
<!-- 로그아웃 -->
<c:if test="${param.req =='logoutResult' }">
<jsp:include page="../member/logoutResult.jsp"/>
</c:if>
<!-- 회원정보 수정 -->
<c:if test="${param.req =='modifyForm' }">
<jsp:include page="../member/modifyForm.jsp"/>
</c:if>
<!-- 회원정보 수정 -->
<c:if test="${param.req =='modifyResult' }">
<jsp:include page="../member/modifyResult.jsp"/>
</c:if>
<!-- 글쓰기 -->
<c:if test="${param.req =='boardWriteForm' }">
<jsp:include page="../board/boardWriteForm.jsp"/>
</c:if>
<!-- 글쓰기 확인 -->
<c:if test="${param.req =='boardWriteResult' }">
<jsp:include page="../board/boardWriteResult.jsp"/>
</c:if>
<!-- 글목록 -->
<c:if test="${param.req =='boardListResult' }">
<jsp:include page="../board/boardListResult.jsp"/>
</c:if>
<!-- 글 보기 -->
<c:if test="${param.req =='boardViewResult' }">
<jsp:include page="../board/boardViewResult.jsp"/>
</c:if>
<!-- 글 수정 -->
<c:if test="${param.req =='boardModifyFormResult' }">
<jsp:include page="../board/boardModifyFormResult.jsp"/>
</c:if>
<!-- 글 수정 확인 -->
<c:if test="${param.req =='boardModifyResult' }">
<jsp:include page="../board/boardModifyResult.jsp"/>
</c:if>
<!-- 글 삭제 -->
<c:if test="${param.req =='boardDeleteResult' }">
<jsp:include page="../board/boardDeleteResult.jsp"/>
</c:if>
<!-- imageboard -->
<!-- 상품 등록 -->
<c:if test="${param.req =='imageboardWriteForm' }">
<jsp:include page="../imageboard/imageboardWriteForm.jsp"/>
</c:if>
<!-- 상품 등록 확인 -->
<c:if test="${param.req =='imageboardWriteResult' }">
<jsp:include page="../imageboard/imageboardWriteResult.jsp"/>
</c:if>
<!-- 상품 목록 -->
<c:if test="${param.req =='iamgeboardListResult' }">
<jsp:include page="../imageboard/iamgeboardListResult.jsp"/>
</c:if>
<!-- 상품 상세 -->
<c:if test="${param.req =='iamgeboardViewResult' }">
<jsp:include page="../imageboard/iamgeboardViewResult.jsp"/>
</c:if>
<!-- 상품 수정 -->
<c:if test="${param.req =='imageboardModifyFormResult' }">
<jsp:include page="../imageboard/imageboardModifyFormResult.jsp"/>
</c:if>
<!-- 상품 수정 확인 -->
<c:if test="${param.req =='imageboardModifyResult' }">
<jsp:include page="../imageboard/imageboardModifyResult.jsp"/>
</c:if>
<!-- 상품 삭제 -->
<c:if test="${param.req =='imageboardDeleteResult' }">
<jsp:include page="../imageboard/imageboardDeleteResult.jsp"/>
</c:if>
</section>
<!-- // section end -->
</main>
<footer>
<h2>Copyright©</h2>
</footer>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>body.jsp</title>
<style type="text/css">
img {
position:relative;
width: 500px;
height: 500px;
}
#item {
position:absolute;
width: 130px;
height:auto;
top:350px;
left:400px;
touch-action: none;
user-select: none;
}
#item:hover {
cursor: pointer;
border-width: 20px;
}
#item2 {
position:absolute;
width: 130px;
height:auto;
top:420px;
left:300px;
touch-action: none;
user-select: none;
}
#item2:hover {
cursor: pointer;
border-width: 20px;
}
</style>
</head>
<body>
<div id="outerContainer">
<div id="container">
<img alt="home 이미지" src="../image/home.jpg"/>
<img id="item" src="../image/zz.png"/>
<img id="item2" src="https://blog.kakaocdn.net/dn/b15sew/btqCLcWSfTC/0eCl75W4fMEiKbtgL3Tg30/img.gif"/>
</div>
</div>
<script>
var dragItem = document.querySelector("#item");
var container = document.querySelector("#container");
var active = false;
var currentX;
var currentY;
var initialX;
var initialY;
var xOffset = 0;
var yOffset = 0;
container.addEventListener("touchstart", dragStart, false);
container.addEventListener("touchend", dragEnd, false);
container.addEventListener("touchmove", drag, false);
container.addEventListener("mousedown", dragStart, false);
container.addEventListener("mouseup", dragEnd, false);
container.addEventListener("mousemove", drag, false);
function dragStart(e) {
if (e.type === "touchstart") {
initialX = e.touches[0].clientX - xOffset;
initialY = e.touches[0].clientY - yOffset;
} else {
initialX = e.clientX - xOffset;
initialY = e.clientY - yOffset;
}
if (e.target === dragItem) {
active = true;
}
}
function dragEnd(e) {
initialX = currentX;
initialY = currentY;
active = false;
}
function drag(e) {
if (active) {
e.preventDefault();
if (e.type === "touchmove") {
currentX = e.touches[0].clientX - initialX;
currentY = e.touches[0].clientY - initialY;
} else {
currentX = e.clientX - initialX;
currentY = e.clientY - initialY;
}
xOffset = currentX;
yOffset = currentY;
setTranslate(currentX, currentY, dragItem);
}
}
function setTranslate(xPos, yPos, el) {
el.style.transform = "translate3d(" + xPos + "px, " + yPos + "px, 0)";
}
</script>
</body>
</html>
CREATE TABLE member(
name VARCHAR2(30) NOT NULL, -- 이름
id VARCHAR2(30) PRIMARY KEY, -- id
pwd VARCHAR2(30) NOT NULL, -- 비밀번호
gender VARCHAR2(3), -- 성별
email VARCHAR2(20), -- 이메일
domain VARCHAR2(20), -- domain
tel VARCHAR2(13), -- 전화번호
addr VARCHAR2(100), -- 주소
logtime DATE -- 생성일자
);
-- board 테이블( 게시판 )
CREATE TABLE board(
seq NUMBER NOT NULL, -- 글번호
id VARCHAR2(30) NOT NULL, -- 아이디
name VARCHAR2(30) NOT NULL, -- 작성자
subject VARCHAR2(50) NOT NULL, -- 제목
content VARCHAR2(1000) NOT NULL, -- 내용
hit NUMBER DEFAULT 0, -- 조회수
logtime DATE DEFAULT SYSDATE -- 작성일자
);
DESC board;
SELECT * FROM board;
-- seq 컬럼에 적용하는 board_seq 시퀀스 객체 생성
CREATE SEQUENCE board_seq NOCACHE NOCYCLE;
DROP SEQUENCE board_seq;
-- imageBoard table
DROP TABLE imageboard PURGE;
DROP SEQUENCE seq_imageboard;
CREATE TABLE imageboard(
seq NUMBER NOT NULL, -- 글번호
imageId VARCHAR2(20) NOT NULL, -- 상품 코드
imageName VARCHAR2(40) NOT NULL, -- 상품 이름
imagePrice NUMBER NOT NULL, -- 상품 단가
imageQty NUMBER NOT NULL, -- 상품 수량
imageContent VARCHAR2(1000) NOT NULL, -- 상품 설명
imageFile VARCHAR2(200), -- 파일명
logtime DATE DEFAULT SYSDATE -- 등록일자
);
DESC imageboard;
SELECT * FROM imageboard;
CREATE SEQUENCE seq_imageboard NOCACHE NOCYCLE;
// 회원 정보 입력 확인
function checkWrite(){
if(document.writeForm.name.value==""){
alert("이름을 입력하세요");
document.writeForm.name.focus();
}else if(document.writeForm.id.value==""){
alert("아이디를 입력하세요");
document.writeForm.id.focus();
}else if(document.writeForm.pwd.value==""){
alert("비밀번호을 입력하세요");
document.writeForm.pwd.focus();
}else if(document.writeForm.pwd.value!=document.writeForm.repwd.value){
alert("비밀번호를 확인하세요");
document.writeForm.repwd.focus();
}else if(document.writeForm.email.value==""){
alert("이메일을 입력하세요");
document.writeForm.email.focus();
}else if(document.writeForm.tel_1.value==""){
alert("전화번호를 모두 입력하세요");
document.writeForm.tel_1.focus();
}else if(document.writeForm.tel_2.value==""){
alert("전화번호를 모두 입력하세요");
document.writeForm.tel_2.focus();
}else if(document.writeForm.tel_3.value==""){
alert("전화번호를 모두 입력하세요");
document.writeForm.tel_3.focus();
}else if(document.writeForm.addr.value==""){
alert("주소를 입력하세요");
document.writeForm.addr.focus();
} else {
document.writeForm.submit();
}
}
// ID 중복 확인
function checkId(){
let uid = document.writeForm.id.value;
if(uid == "" || uid ==0) {
alert("아이디를 입력하세요~");
document.writeForm.id.focus();
}else {
window.open("../member/checkId.jsp?id="+uid,'','left=200, top=200,width=500,height=300');
}
}
// 로그인
function login(){
if(document.loginForm.id.value==""){
alert("아이디 입력");
document.loginForm.id.focus();
}
else if(document.loginForm.pwd.value==""){
alert("비밀번호 입력");
document.loginForm.pwd.focus();
} else {
document.loginForm.submit();
}
}
//정보 수정
function checkModify(){
if(document.modifyForm.name.value==""){
alert("이름을 입력하세요");
document.modifyForm.name.focus();
}else if(document.modifyForm.pwd.value==""){
alert("비밀번호을 입력하세요");
document.modifyForm.pwd.focus();
}else if(document.modifyForm.pwd.value!=document.modifyForm.repwd.value){
alert("비밀번호를 확인하세요");
document.modifyForm.repwd.focus();
}else if(document.modifyForm.email.value==""){
alert("이메일을 입력하세요");
document.modifyForm.email.focus();
}else if(document.modifyForm.tel_1.value==""){
alert("전화번호를 모두 입력하세요");
document.modifyForm.tel_1.focus();
}else if(document.modifyForm.tel_2.value==""){
alert("전화번호를 모두 입력하세요");
document.modifyForm.tel_2.focus();
}else if(document.modifyForm.tel_3.value==""){
alert("전화번호를 모두 입력하세요");
document.modifyForm.tel_3.focus();
}else if(document.modifyForm.addr.value==""){
alert("주소를 입력하세요");
document.modifyForm.addr.focus();
}else {
document.modifyForm.submit();
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>writeForm</title>
<style type="text/css">
table, tr, td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
}
.title {
width: 120px;
text-align: center;
}
</style>
<script type="text/javascript" src="../script/memberScript.js?v=35"></script>
</head>
<body>
<h2>회원 가입</h2>
<br>
<form name="writeForm" action="../member/write.jsp" method="post">
<table>
<tr>
<td class="title">이름</td>
<td>
<input type="text" name="name">
</td>
</tr>
<tr>
<td class="title">I D</td>
<td>
<input type="text" name="id" autocomplete="nope">
<input type="button" name="cb" value="중복체크" onclick="checkId()"/>
</td>
</tr>
<tr>
<td class="title">P W</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr>
<td class="title">PWC</td>
<td><input type="password" name="repwd"></td>
</tr>
<tr>
<td class="title">성별</td>
<td>
<input type="radio" name="gender" value="M" checked />
<label for="genderM"> 남 </label>
<input type="radio" name="gender" value="F">
<label for="genderF"> 여 </label>
</td>
</tr>
<tr>
<td class="title">E-mail</td>
<td>
<input type="text" name="email" size="10"> @
<select name="domain">
<option value="naver.com">naver.com</option>
<option value="gmain.com">gmain.com</option>
</select>
</td>
</tr>
<tr>
<td class="title">핸드폰</td>
<td>
<input type="text" name="tel_1" size="3" maxlength="3"> -
<input type="text" name="tel_2" size="4" maxlength="4"> -
<input type="text" name="tel_3" size="4" maxlength="4">
</td>
</tr>
<tr>
<td class="title">주소</td>
<td>
<input type="text" name="addr" size="50">
</td>
</tr>
<tr>
<td class="title" colspan="2">
<input type="button" value="회원가입" onclick="checkWrite()" />
<input type="reset" value="다시작성" />
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="member.dao.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String id = request.getParameter("id");
MemberDAO memberDAO = new MemberDAO();
boolean exist = memberDAO.isExistId(id);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>checkId.jsp</title>
</head>
<body>
<h2>ID 중복 확인</h2>
<form action="checkId.jsp" method="post">
<%if(exist){ %>
<p><%=id %> 사용중인 id </p>
<br>
<label>아이디 : </label><input type="text" name="id"/> <input type="submit" value="중복체크"/>
<%} else { %>
<p><%=id %> 사용 가능 id</p>
<br>
<input type="button" value="사용" onclick="checkIdClose()"/>
<%} %>
</form>
<script type="text/javascript">
function checkIdClose() {
opener.writeForm.id.value="<%=id%>";
window.close();
opener.writeForm.pwd.focus();
document.writeForm.cb
}
</script>
</body>
</html>
<%@page import="member.dao.MemberDAO"%>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String id = request.getParameter("id");
String pwd = request.getParameter("pwd");
String repwd = request.getParameter("repwd");
String gender = request.getParameter("gender");
String email = request.getParameter("email");
String domain = request.getParameter("domain");
String tel_1 = request.getParameter("tel_1");
String tel_2 = request.getParameter("tel_2");
String tel_3 = request.getParameter("tel_3");
String tel = tel_1 + "-" + tel_2 + "-" + tel_3;
String addr = request.getParameter("addr");
MemberDTO memberDTO = new MemberDTO();
memberDTO.setName(name);
memberDTO.setId(id);
memberDTO.setPwd(pwd);
memberDTO.setGender(gender);
memberDTO.setEmail(email);
memberDTO.setDomain(domain);
memberDTO.setTel(tel);
memberDTO.setAddr(addr);
MemberDAO memberDAO = new MemberDAO();
int su = memberDAO.write(memberDTO);
request.setAttribute("res", su);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=writeResult");
dispatcher.forward(request, response);
%>
<%@ 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>writeResult.jsp</title>
<style type="text/css">
p {font-size: 24px;}
</style>
</head>
<body>
<h2>회원가입 확인</h2>
<br>
<c:if test="${res !=0 }">
<p>회원가입 성공</p>
</c:if>
<c:if test="${res ==0 }">
<p>회원가입 실패</p>
</c:if>
<br><br>
<input type="button" value="main" onclick="location.href='../main/index.jsp'"/>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="root" value="${pageContext.request.contextPath }" scope="application"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>loginForm</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
tr:last-child > td{
text-align: center;
}
th, td {
padding: 4px;
}
.title {
width: 120px;
}
</style>
<script type="text/javascript" src="../script/memberScript.js?v=2"></script>
</head>
<body>
<h2>로그인</h2>
<form name="loginForm" action="../member/login.jsp" method="post">
<table>
<tr>
<th class="title"> 아이디 </th>
<td><input type="text" name="id"/></td>
</tr>
<tr>
<th class="title"> 비밀번호 </th>
<td><input type="password" name="pwd"/></td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="로그인" onclick="login()"/>
<input type="button" value="회원가입" onclick="location.href='../main/index.jsp?req=writeForm'"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="member.dao.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%--
URL 인코딩
- URI 에서 사용할 수 없는 문자를 인코딩
URLEncoder.encode(변수명, "utf-8")
--%>
<%
String id = request.getParameter("id");
String pwd = request.getParameter("pwd");
MemberDAO memberDAO = new MemberDAO();
String name = memberDAO.login(id,pwd);
if(name!=""){
// session 설정
session.setAttribute("memberId", id);
session.setAttribute("memberName", name);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=loginOk");
dispatcher.forward(request, response);
} else {
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=loginFail");
dispatcher.forward(request, response);
}
%>
<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>loginOk.jsp</title>
<style type="text/css">
img {
width: 300px;
height: 200px;
cursor: pointer;
}
</style>
</head>
<body>
<br>
<img src="../image/home.jpg" onclick="location.href='../main/index.jsp'"/>
<br>
<h2>ID : ${sessionScope.memberName } 이게 이름? ㅋㅋ</h2>
<br>
<input type="button" value="main" onclick="location.href='../main/index.jsp'"/>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>loginFail.jsp</title>
<style type="text/css">
button {
width: 100px;
height: 30px;
}
</style>
</head>
<body>
<br>
<h2>아이디 또는 비밀번호가 틀렸습니다</h2>
<br>
<button onclick="location.href='../main/index.jsp'"> main </button>
<button onclick="location.href='../main/index.jsp?req=loginForm'"> 로그인 </button>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
// session 삭제
session.removeAttribute("memberId");
session.removeAttribute("memberName");
session.invalidate();
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=logoutResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>logoutResult.jsp</title>
<script type="text/javascript">
window.onload = function(){
alert("로그아웃 되었습니다.");
location.href="../main/index.jsp"
}
</script>
</head>
<body>
</body>
</html>
<%@page import="member.dto.MemberDTO"%>
<%@page import="member.dao.MemberDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String id = (String)session.getAttribute("memberId");
// 현재 접속된 회원정보 가져오기
MemberDAO memberDAO = new MemberDAO();
MemberDTO data = new MemberDTO();
data = memberDAO.bring(id);
String name = data.getName();
String pwd = data.getPwd();
String gender = data.getGender();
String email = data.getEmail();
String domain = data.getDomain();
String tel_1 = data.getTel().substring(0,3);
String tel_2 = data.getTel().substring(4,8);
String tel_3 = data.getTel().substring(9);
String addr = data.getAddr();
request.setAttribute("name", name);
request.setAttribute("id", id);
request.setAttribute("pwd", pwd);
request.setAttribute("gender", gender);
request.setAttribute("email", email);
request.setAttribute("domain", domain);
request.setAttribute("tel_1", tel_1);
request.setAttribute("tel_2", tel_2);
request.setAttribute("tel_3", tel_3);
request.setAttribute("addr", addr);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=modifyForm");
dispatcher.forward(request, response);
%>
<%@ 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>modifyForm.jsp</title>
<style type="text/css">
table, tr, td {
border: 1px solid black;
border-collapse: collapse;
padding: 10px;
}
.title {
width: 120px;
text-align: center;
}
</style>
<script type="text/javascript" src="../script/memberScript.js?v=3"></script>
</head>
<body>
<h2>회원정보 수정</h2>
<br>
<form name="modifyForm" action="../member/modify.jsp" method="post">
<table>
<tr>
<td class="title">이름</td>
<td><input type="text" name="name" value="${name }" autocomplete="nope"></td>
</tr>
<tr>
<td class="title">I D</td>
<td><input type="text" name="id" value="${id }" readonly/></td>
</tr>
<tr>
<td class="title">P W</td>
<td><input type="text" name="pwd" value="${pwd }" ></td>
</tr>
<tr>
<td class="title">PWC</td>
<td><input type="text" name="repwd"></td>
</tr>
<tr>
<td class="title">성별</td>
<td>
<c:if test="${gender =='M'}">
<input type="radio" name="gender" value="M" checked/><label for="genderM"> 남 </label>
<input type="radio" name="gender" value="F"/><label for="genderF"> 여 </label>
</c:if>
<c:if test="${gender =='F'}">
<input type="radio" name="gender" value="M"/><label for="genderM"> 남 </label>
<input type="radio" name="gender" value="F" checked /><label for="genderF"> 여 </label>
</c:if>
</td>
</tr>
<tr>
<td class="title">E-mail</td>
<td>
<input type="text" name="email" size="10" value="${email }" autocomplete="nope"/> @
<input type="text" name="domain" value="${domain }"/>
</td>
</tr>
<tr>
<td class="title">핸드폰</td>
<td>
<input type="text" name="tel_1" value="${tel_1 }" size="3" maxlength="3"> -
<input type="text" name="tel_2" value="${tel_2 }" size="4" maxlength="4"> -
<input type="text" name="tel_3" value="${tel_3 }" size="4" maxlength="4">
</td>
</tr>
<tr>
<td class="title">주소</td>
<td><input type="text" name="addr" value="${addr }" size="50"></td>
</tr>
<tr>
<td class="title" colspan="2">
<input type="button" value="수정완료" onclick="checkModify()"/>
<input type="reset" value="다시작성"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="member.dao.MemberDAO"%>
<%@page import="member.dto.MemberDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String id = request.getParameter("id");
String pwd = request.getParameter("pwd");
String repwd = request.getParameter("repwd");
String gender = request.getParameter("gender");
String email = request.getParameter("email");
String domain = request.getParameter("domain");
String tel_1 = request.getParameter("tel_1");
String tel_2 = request.getParameter("tel_2");
String tel_3 = request.getParameter("tel_3");
String tel = tel_1 + "-" + tel_2 + "-" + tel_3;
String addr = request.getParameter("addr");
MemberDTO memberDTO = new MemberDTO();
MemberDAO memberDAO = new MemberDAO();
memberDTO.setName(name);
memberDTO.setId(id);
memberDTO.setPwd(pwd);
memberDTO.setGender(gender);
memberDTO.setEmail(email);
memberDTO.setDomain(domain);
memberDTO.setTel(tel);
memberDTO.setAddr(addr);
int su = memberDAO.update(memberDTO);
request.setAttribute("res", su);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=modifyResult");
dispatcher.forward(request, response);
%>
<%@ 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>modifyResult</title>
</head>
<body>
<h2>회원정보 수정</h2>
<br>
<c:if test="${res != 0 }">
회원정보가 수정되었습니다
</c:if>
<c:if test="${res == 0 }">
회원정보가 수정 실패
</c:if>
<input type="button" value="main" onclick="location.href='../main/index.jsp'"/>
</body>
</html>
function checkBoardWrite(){
if(document.boardWriteForm.subject.value ==""){
alert("제목 입력");
document.boardWriteForm.subject.focus();
}else if(document.boardWriteForm.content.value ==""){
alert("내용 입력");
document.boardWriteForm.content.focus();
} else {
document.boardWriteForm.submit();
}
}
//글 수정
function checkBoardModify(){
if(document.boardModifyForm.subject.value ==""){
alert("제목 입력");
document.boardModifyForm.subject.focus();
}else if(document.boardModifyForm.content.value==""){
alert("내용 입력");
document.boardModifyForm.content.focus();
} else {
document.boardModifyForm.submit();
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>boardWriteForm.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 4px;
}
textarea {
resize: none;
}
</style>
<script type="text/javascript" src="../script/boardScript.js?after"></script>
</head>
<body>
<h1>글쓰기</h1>
<br>
<form name="boardWriteForm" action="../board/boardWrite.jsp" method="post">
<table>
<tr>
<th> 제 목 </th>
<td><input type="text" name="subject" size="50"/></td>
</tr>
<tr>
<th> 내 용 </th>
<td>
<textarea rows="20" cols="52" name="content"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="완료" onclick="checkBoardWrite()"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="board.dao.BoardDAO"%>
<%@page import="board.dto.BoardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String subject = request.getParameter("subject");
String content = request.getParameter("content");
String id = (String)session.getAttribute("memberId");
String name = (String)session.getAttribute("memberName");
BoardDTO dto = new BoardDTO();
dto.setName(name);
dto.setId(id);
dto.setSubject(subject);
dto.setContent(content);
BoardDAO dao = new BoardDAO();
int write = dao.write(dto);
request.setAttribute("write", write);
request.setAttribute("subject", subject);
request.setAttribute("content", content);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=boardWriteResult");
dispatcher.forward(request, response);
%>
<%@ 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>boardWrite.jsp</title>
</head>
<body>
<h1>글쓰기 확인</h1>
<br>
<c:if test="${write>0 }">
<h1>글쓰기 성공</h1>
<table>
<tr>
<th>제목</th><td>${subject }</td>
</tr>
<tr>
<th>내용</th><td>${content }</td>
</tr>
</table><br>
</c:if>
<c:if test="${write==0 }">
<h1>글쓰기 실패</h1>
</c:if>
<input type="button" value="main" onclick="location.href='../main/index.jsp'"/>
</body>
</html>
<%@page import="java.util.ArrayList"%>
<%@page import="board.dto.BoardDTO"%>
<%@page import="board.dao.BoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int pg = Integer.parseInt(request.getParameter("pg"));
int article = 3; // 한 페이지 글 목록 수
int currentPage = pg; // 현재 페이지
int startNum = (currentPage -1) * article + 1; // 시작 글번호
int lastNum = startNum + article - 1; // 마지막 글 번호
BoardDAO dao = new BoardDAO();
ArrayList<BoardDTO> list = dao.boardList(startNum, lastNum);
// 페이징
int totalArticle = dao.getTotalArticle(); // 전체 글 수
int totalPage = (totalArticle-1) / article +1; //전체 페이지 수
int block = 3; // 페이지 블록
int startPage = (currentPage-1)/block * block + 1;
int endPage = startPage + block -1;
if(endPage > totalPage) endPage = totalPage;
request.setAttribute("pg", pg);
request.setAttribute("list", list);
request.setAttribute("totalPage", totalPage);
request.setAttribute("startPage", startPage);
request.setAttribute("endPage", endPage);
request.setAttribute("block", block);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=boardListResult");
dispatcher.forward(request, response);
%>
<!-- board/boardListResult.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>boardListResult.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
text-align: center;
}
#paging_block {
width: 1000px;
text-align: center;
}
#paging {
color: black;
text-decoration: none;
}
#currentPaging {
color: red;
text-decoration: underline;
}
</style>
</head>
<body>
<h1>글목록</h1>
<br/>
<table>
<tr>
<th width="100px"> 글번호 </th>
<th width="500px"> 제 목 </th>
<th width="150px"> 작성자 </th>
<th width="150px"> 작성일 </th>
<th width="100px"> 조회수 </th>
</tr>
<c:forEach var="boardDTO" items="${list }">
<tr>
<td>${boardDTO.seq }</td>
<td>
<a href="#" onclick="isLogin(${boardDTO.seq }, ${pg })">${boardDTO.subject }</a>
</td>
<td>${boardDTO.name }</td>
<td>${boardDTO.logtime }</td>
<td>${boardDTO.hit }</td>
</tr>
</c:forEach>
</table>
<br/><br/>
<!-- 페이징 -->
<div id="paging_block">
<c:if test="${startPage > block }">
[ <a href="boardList.jsp?pg=${startPage-1 }" id="paging"> 이전 </a> ]
</c:if>
<c:forEach var="i" begin="${startPage }" end="${endPage }" step="1">
<c:if test="${i == pg }">
[ <a href="boardList.jsp?pg=${i }" id="currentPaging"> ${i } </a> ]
</c:if>
<c:if test="${i != pg }">
[ <a href="boardList.jsp?pg=${i }" id="paging"> ${i } </a> ]
</c:if>
</c:forEach>
<c:if test="${endPage < totalPage }">
[ <a href="boardList.jsp?pg=${endPage+1 }" id="paging"> 다음 </a> ]
</c:if>
</div>
<br/><br/>
<input type="button" value="main" onclick="location.href='../main/index.jsp'"/>
<!-- script -->
<script type="text/javascript">
function isLogin(seq, pg){
<%if(session.getAttribute("memberId") == null){%>
alert("로그인하세요~");
<%} else {%>
location.href="../board/boardView.jsp?seq="+seq+"&pg="+pg;
<%} %>
}
</script>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="board.dao.BoardDAO"%>
<%@page import="board.dto.BoardDTO"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
BoardDAO dao = new BoardDAO();
BoardDTO dto = new BoardDTO();
dao.updateHit(seq);
dto = dao.boardView(seq);
request.setAttribute("seq", seq);
request.setAttribute("pg", pg);
request.setAttribute("subject", dto.getSubject());
request.setAttribute("name", dto.getName());
request.setAttribute("hit", dto.getHit());
request.setAttribute("content", dto.getContent());
request.setAttribute("id", dto.getId());
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=boardViewResult");
dispatcher.forward(request, response);
%>
<%@ 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>boardView.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
text-align: center;
vertical-align: middle;
}
</style>
</head>
<body>
<h1>글보기</h1>
<br>
<table>
<tr>
<td colspan="3">${subject }</td>
</tr>
<tr>
<td width="200px">글번호 : ${seq }</td>
<td width="200px">작성자 : ${name }</td>
<td width="200px">조회수 : ${hit }</td>
</tr>
<tr>
<td colspan="3" height="300px" valign="top">
<pre>${content }</pre>
</td>
</tr>
</table>
<br><br>
<input type="button" value="글목록" onclick="location.href='boardList.jsp?pg=${pg}'"/>
<c:if test="${sessionScope.memberId.equals(id) }">
<input type="button" value="글수정" onclick="location.href='boardModifyForm.jsp?seq=${seq}&pg=${pg }'">
<input type="button" value="글삭제" onclick="location.href='../board/boardDelete.jsp?seq=${seq}&pg=${pg }'">
</c:if>
</body>
</html>
<%@page import="board.dao.BoardDAO"%>
<%@page import="board.dto.BoardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
BoardDAO dao = new BoardDAO();
BoardDTO dto = new BoardDTO();
dto = dao.boardView(seq);
request.setAttribute("seq", seq);
request.setAttribute("pg", pg);
request.setAttribute("subject", dto.getSubject());
request.setAttribute("name", dto.getName());
request.setAttribute("hit", dto.getHit());
request.setAttribute("content", dto.getContent());
request.setAttribute("id", dto.getId());
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=boardModifyFormResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>boardModifyFormResult.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
text-align: center;
}
textarea {
resize: none;
}
</style>
<script type="text/javascript" src="../script/boardScript.js?v=33"></script>
</head>
<body>
<h1>글수정</h1>
<br>
<form name="boardModifyForm" action="../board/boardModify.jsp" method="post">
<input type="hidden" name="seq" value="${seq }"/>
<input type="hidden" name="pg" value="${pg }"/>
<table>
<tr>
<th>제 목</th>
<td><input type="text" name="subject" value="${subject }" size="50" /></td>
</tr>
<tr>
<th>내 용</th>
<td>
<textarea rows="20" cols="52" name="content">${content }</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="완료" onclick="checkBoardModify()"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="board.dto.BoardDTO"%>
<%@page import="board.dao.BoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
String subject = request.getParameter("subject");
String content = request.getParameter("content");
BoardDTO dto = new BoardDTO();
dto.setSeq(seq);
dto.setSubject(subject);
dto.setContent(content);
BoardDAO dao = new BoardDAO();
int su = dao.modify(dto);
request.setAttribute("su", su);
request.setAttribute("pg", pg);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=boardModifyResult");
dispatcher.forward(request, response);
%>
<%@ 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>boardModifyResult.jsp</title>
</head>
<body>
<script type="text/javascript">
window.onload = function (){
if(${su} != 0){
alert("글 수정 완료");
location.href="../board/boardList.jsp?pg="+${pg};
} else {
alert("글 수정 실패");
history.back(-1);
}
}
</script>
</body>
</html>
<%@page import="board.dao.BoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
BoardDAO dao = new BoardDAO();
int su = dao.delete(seq);
request.setAttribute("pg", pg);
request.setAttribute("su", su);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=boardDeleteResult");
dispatcher.forward(request, response);
%>
<%@ 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>boardDelete.jsp</title>
</head>
<body>
<script type="text/javascript">
window.onload = function (){
if(${su} != 0){
alert("글 삭제 완료");
location.href="../board/boardList.jsp?pg="+${pg};
} else {
alert("글 삭제 실패");
history.back(-1);
}
}
</script>
</body>
</html>
// 상품등록
function imageWrite(){
if(document.imageboardWriteForm.imageId.value=="img_"||document.imageboardWriteForm.imageId.value==""){
alert("상품 코드를 입력하세요");
document.imageboardWriteForm.imageId.focus();
}
else if(document.imageboardWriteForm.imageName.value==""){
alert("상품명을 입력하세요");
document.imageboardWriteForm.imageName.focus();
}
else if(document.imageboardWriteForm.imagePrice.value==""){
alert("상품가격을 입력하세요");
document.imageboardWriteForm.imagePrice.focus();
}
else if(document.imageboardWriteForm.imageQty.value==""){
alert("상품 수량을 입력하세요");
document.imageboardWriteForm.imageQty.focus();
}
else if(document.imageboardWriteForm.imageContent.value==""){
alert("상품설명을 입력하세요");
document.imageboardWriteForm.imageContent.focus();
}
else if(document.imageboardWriteForm.imageFile.value==""){
alert("첨부파일 선택하세요");
document.imageboardWriteForm.imageFile.focus();
}
else {
document.imageboardWriteForm.submit();
}
}
function imageModify(){
if(document.imageboardModifyForm.imageId.value=="img_"||document.imageboardModifyForm.imageId.value==""){
alert("상품 코드를 입력하세요");
document.imageboardModifyForm.imageId.focus();
}
else if(document.imageboardModifyForm.imageName.value==""){
alert("상품명을 입력하세요");
document.imageboardModifyForm.imageName.focus();
}
else if(document.imageboardModifyForm.imagePrice.value==""){
alert("상품가격을 입력하세요");
document.imageboardModifyForm.imagePrice.focus();
}
else if(document.imageboardModifyForm.imageQty.value==""){
alert("상품 수량을 입력하세요");
document.imageboardModifyForm.imageQty.focus();
}
else if(document.imageboardModifyForm.imageContent.value==""){
alert("상품설명을 입력하세요");
document.imageboardModifyForm.imageContent.focus();
}
else if(document.imageboardModifyForm.imageFile.value==""){
alert("첨부파일 선택하세요");
document.imageboardModifyForm.imageFile.focus();
}
else {
document.imageboardModifyForm.submit();
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>imageboardWriteForm.jsp</title>
<style type="text/css">
table, tr, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
textarea {
resize: none;
}
</style>
<script type="text/javascript" src="../script/imageboardScript.js?after"></script>
</head>
<body>
<h2>상품 등록</h2>
<br>
<form name="imageboardWriteForm" action="../imageboard/imageboardWrite.jsp" method="post" enctype="multipart/form-data">
<table>
<tr>
<th width="100px"> 상품 코드 </th>
<td width="300px"><input type="text" name="imageId" value="img_" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품명 </th>
<td width="300px"><input type="text" name="imageName" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품 가격 </th>
<td width="300px"><input type="number" name="imagePrice" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품 수량 </th>
<td width="300px"><input type="number" name="imageQty" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품 설명 </th>
<td width="300px"><textarea name="imageContent" rows="10" cols="52"></textarea> </td>
</tr>
<tr>
<td colspan="2"><input type="file" name="imageFile" size="50px"> </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="등록" onclick="imageWrite()"/>
<input type="reset" value="다시 작성" />
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="imageboard.dao.ImageBoardDAO"%>
<%@page import="imageboard.dto.ImageBoardDTO"%>
<%@page import="java.io.File"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String realFolder = request.getServletContext().getRealPath("/storage");
MultipartRequest mr = new MultipartRequest(request, realFolder, 1024*1024*5, "utf-8");
String imageId = mr.getParameter("imageId");
String imageName = mr.getParameter("imageName");
int imagePrice = Integer.parseInt(mr.getParameter("imagePrice"));
int imageQty = Integer.parseInt(mr.getParameter("imageQty"));
String imageContent = mr.getParameter("imageContent");
String imageFile = mr.getOriginalFileName("imageFile");
ImageBoardDTO dto = new ImageBoardDTO();
dto.setImageId(imageId);
dto.setImageName(imageName);
dto.setImagePrice(imagePrice);
dto.setImageQty(imageQty);
dto.setImageContent(imageContent);
dto.setImageFile(imageFile);
ImageBoardDAO dao = new ImageBoardDAO();
int res = dao.imageboardWrite(dto);
request.setAttribute("res", res);
request.setAttribute("imageName", imageName);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=imageboardWriteResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>imageboardWriteResult.jsp</title>
<script type="text/javascript">
window.onload = function(){
if(${res ==1}){
alert("${imageName} 요 상품등록성공");
location.href="../main/index.jsp"
} else {
alert("상품등록실패");
history.back(-1);
}
}
</script>
</head>
<body>
</body>
</html>
<%@page import="imageboard.dto.ImageBoardDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="imageboard.dao.ImageBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int pg = Integer.parseInt(request.getParameter("pg"));
int article = 3; // 한 페이지 글 목록 수
int currentPage = pg; // 현재 페이지
int startNum = (currentPage -1) * article + 1; // 시작 글번호
int lastNum = startNum + article - 1; // 마지막 글 번호
ImageBoardDAO dao = new ImageBoardDAO();
ArrayList<ImageBoardDTO> list = dao.iamgeboardList(startNum, lastNum);
// 페이징
int totalArticle = dao.getTotalArticle(); // 전체 글 수
int totalPage = (totalArticle-1) / article +1; //전체 페이지 수
int block = 3; // 페이지 블록
int startPage = (currentPage-1)/block * block + 1;
int endPage = startPage + block -1;
if(endPage > totalPage) endPage = totalPage;
request.setAttribute("pg", pg);
request.setAttribute("list", list);
request.setAttribute("totalPage", totalPage);
request.setAttribute("startPage", startPage);
request.setAttribute("endPage", endPage);
request.setAttribute("block", block);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=iamgeboardListResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>iamgeboardListResult.jsp</title>
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
td {
text-align: center;
}
#paging_block {
width: 1000px;
text-align: center;
}
#paging {
color: black;
text-decoration: none;
}
#currentPaging {
color: red;
text-decoration: underline;
}
</style>
</head>
<body>
<h1>상품 목록</h1>
<br/>
<table>
<tr>
<th width="50px"> 번호 </th>
<th width="90px"> 이미지 </th>
<th width="200px"> 상품명 </th>
<th width="120px"> 가격 </th>
<th width="120px"> 수량 </th>
<th width="120px"> 합계 </th>
</tr>
<c:forEach var="dto" items="${list }">
<tr>
<td>${dto.seq }</td>
<td>
<a href="#" onclick="isLogin(${dto.seq }, ${pg })">
<img src="../storage/${dto.imageFile }" width="80px" height="80px"/>
</a>
</td>
<td>${dto.imageName }</td>
<c:set var="num1" value="${dto.imagePrice }"/>
<td><fmt:formatNumber value="${num1 }"/> 원</td>
<td>${dto.imageQty }</td>
<c:set var="num2" value="${dto.imagePrice * dto.imageQty }"/>
<td><fmt:formatNumber value="${num2 }"/> 원</td>
</tr>
</c:forEach>
</table>
<br/><br/>
<!-- 페이징 -->
<div id="paging_block">
<c:if test="${startPage > block }">
[ <a href="imageboardList.jsp?pg=${startPage-1 }" id="paging"> 이전 </a> ]
</c:if>
<c:forEach var="i" begin="${startPage }" end="${endPage }" step="1">
<c:if test="${i == pg }">
[ <a href="imageboardList.jsp?pg=${i }" id="currentPaging"> ${i } </a> ]
</c:if>
<c:if test="${i != pg }">
[ <a href="imageboardList.jsp?pg=${i }" id="paging"> ${i } </a> ]
</c:if>
</c:forEach>
<c:if test="${endPage < totalPage }">
[ <a href="imageboardList.jsp?pg=${endPage+1 }" id="paging"> 다음 </a> ]
</c:if>
</div>
<br/><br/>
<input type="button" value="main" onclick="location.href='../main/index.jsp'"/>
<!-- script -->
<script type="text/javascript">
function isLogin(seq, pg){
<%if(session.getAttribute("memberId") == null){%>
alert("로그인하세요~");
<%} else {%>
location.href="../imageboard/imageboardView.jsp?seq="+seq+"&pg="+pg;
<%} %>
}
</script>
</body>
</html>
<%@page import="imageboard.dto.ImageBoardDTO"%>
<%@page import="imageboard.dao.ImageBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
ImageBoardDAO dao = new ImageBoardDAO();
ImageBoardDTO dto = new ImageBoardDTO();
dto = dao.imageboardView(seq);
request.setAttribute("seq", seq);
request.setAttribute("pg", pg);
request.setAttribute("imageId", dto.getImageId());
request.setAttribute("imageName", dto.getImageName());
request.setAttribute("imagePrice", dto.getImagePrice());
request.setAttribute("imageQty", dto.getImageQty());
request.setAttribute("imageContent", dto.getImageContent());
request.setAttribute("imageFile", dto.getImageFile());
request.setAttribute("logtime", dto.getLogtime());
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=iamgeboardViewResult");
dispatcher.forward(request, response);
%>
<!-- imageboard/imageboardViewResult.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>imageboardViewResult.jsp</title>
<style type="text/css">
table, t d {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
</style>
</head>
<body>
<h2>상품 정보</h2>
<table border="1">
<tr>
<td rowspan="6">
<img src="../storage/${imageFile }" width="200px" height="200px"/>
</td>
</tr>
<tr>
<td width="300px"> 등록일 : ${logtime }</td>
</tr>
<tr>
<td width="300px"> 상품명 : ${imageName }</td>
</tr>
<tr>
<td width="300px"> 가격 : ${imagePrice }</td>
</tr>
<tr>
<td width="300px"> 수량 : ${imageQty }</td>
</tr>
<tr>
<td width="300px"> 합계 : ${imagePrice * imageQty }</td>
</tr>
<tr>
<td colspan="2" height="200px" valign="top">
<pre>${imageContent }</pre>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<c:if test="${sessionScope.memberId != null }">
<button onclick="location.href='imageboardModifyReady.jsp?seq=${seq}&pg=${pg }'"> 수정 </button>
<button onclick="location.href='imageboardDelete.jsp?seq=${seq}&pg=${pg }'"> 삭제 </button>
</c:if>
</td>
</tr>
</table>
<br/>
</body>
</html>
<%@page import="imageboard.dto.ImageBoardDTO"%>
<%@page import="imageboard.dao.ImageBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
ImageBoardDAO dao = new ImageBoardDAO();
ImageBoardDTO dto = new ImageBoardDTO();
dto = dao.imageboardView(seq);
request.setAttribute("seq", seq);
request.setAttribute("pg", pg);
request.setAttribute("imageId", dto.getImageId());
request.setAttribute("imageName", dto.getImageName());
request.setAttribute("imagePrice", dto.getImagePrice());
request.setAttribute("imageQty", dto.getImageQty());
request.setAttribute("imageContent", dto.getImageContent());
request.setAttribute("imageFile", dto.getImageFile());
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=imageboardModifyFormResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>imageboardModifyFormResult.jsp</title>
<style type="text/css">
table, tr, td {
border: 1px solid #333333;
border-collapse: collapse;
padding: 4px;
}
textarea {
resize: none;
}
</style>
<script type="text/javascript" src="../script/imageboardScript.js?after"></script>
</head>
<body>
<h2>상품 수정</h2>
<br>
<form name="imageboardModifyForm" action="../imageboard/imageboardModify.jsp" method="post" enctype="multipart/form-data">
<input type="hidden" name="seq" value="${seq }"/>
<input type="hidden" name="pg" value="${pg }"/>
<table>
<tr>
<th width="100px"> 상품 코드 </th>
<td width="300px"><input type="text" name="imageId" value="${imageId }" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품명 </th>
<td width="300px"><input type="text" name="imageName" value="${imageName }" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품 가격 </th>
<td width="300px"><input type="number" name="imagePrice" value="${imagePrice }" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품 수량 </th>
<td width="300px"><input type="number" name="imageQty" value="${imageQty }" size="50px"> </td>
</tr>
<tr>
<th width="100px"> 상품 설명 </th>
<td width="300px"><textarea name="imageContent" rows="10" cols="52">${imageContent }</textarea> </td>
</tr>
<tr>
<td colspan="2"><input type="file" name="imageFile" size="50px"> 이전 파일 : ${imageFile }</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="수정" onclick="imageModify()"/>
<input type="reset" value="다시 작성" />
</td>
</tr>
</table>
</form>
</body>
</html>
<%@page import="imageboard.dao.ImageBoardDAO"%>
<%@page import="imageboard.dto.ImageBoardDTO"%>
<%@page import="java.io.File"%>
<%@page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String realFolder = request.getServletContext().getRealPath("/storage");
MultipartRequest mr = new MultipartRequest(request, realFolder, 1024*1024*5, "utf-8");
int pg = Integer.parseInt(mr.getParameter("pg"));
int seq = Integer.parseInt(mr.getParameter("seq"));
String imageId = mr.getParameter("imageId");
String imageName = mr.getParameter("imageName");
int imagePrice = Integer.parseInt(mr.getParameter("imagePrice"));
int imageQty = Integer.parseInt(mr.getParameter("imageQty"));
String imageContent = mr.getParameter("imageContent");
String imageFile = mr.getOriginalFileName("imageFile");
ImageBoardDTO dto = new ImageBoardDTO();
dto.setImageId(imageId);
dto.setImageName(imageName);
dto.setImagePrice(imagePrice);
dto.setImageQty(imageQty);
dto.setImageContent(imageContent);
dto.setImageFile(imageFile);
ImageBoardDAO dao = new ImageBoardDAO();
int res = dao.modify(dto, seq);
request.setAttribute("res", res);
request.setAttribute("imageName", imageName);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=imageboardModifyResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>imageboardWriteResult.jsp</title>
<script type="text/javascript">
window.onload = function(){
if(${res ==1}){
alert("${imageName} 요 상품수정성공");
location.href="../main/index.jsp"
} else {
alert("상품수정실패");
history.back(-1);
}
}
</script>
</head>
<body>
</body>
<%@page import="imageboard.dao.ImageBoardDAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int seq = Integer.parseInt(request.getParameter("seq"));
int pg = Integer.parseInt(request.getParameter("pg"));
ImageBoardDAO dao = new ImageBoardDAO();
int su = dao.delete(seq);
request.setAttribute("pg", pg);
request.setAttribute("su", su);
RequestDispatcher dispatcher = request.getRequestDispatcher("../main/index.jsp?req=imageboardDeleteResult");
dispatcher.forward(request, response);
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>imageboardDeleteResult.jsp</title>
</head>
<body>
<script type="text/javascript">
window.onload = function(){
if(${su==1}){
alert("삭제 완료");
location.href="../imageboard/imageboardList.jsp?pg="+${pg};
}else{
alert("글 삭제 실패");
history.back(-1);
}
}
</script>
</body>
</html>