로그인

로그인메인 만들어서 로그인 상태에서는 로그아웃창이 나오고, 로그아웃 상태에서는 로그인창

아이디저장

<%
String saveok = (String) session.getAttribute("saveok");
String myid = "";
if (saveok != null) {
	myid = (String) session.getAttribute("myid");
}
%>
<tr>
	<td colspan="2" align="right">
			<input type="checkbox" name="cbsave" <%=saveok == null ? "" : "checked"%>>
						아이디저장
	</td>
</tr>
<tr>
	<th width="150" bgcolor="#DCE6E7" style="text-align: center; vertical-align: middle">아이디</th>
		<td>
				<input type="text" name="id" class="form-control" required="required" style="width: 400px" value="<%=myid%>">
		</td>
</tr>

방명록

회원만 작성하도록

테이블 생성

create table guest(
num smallint auto_increment primary key,
myid varchar(20),
content varchar(2000),
photoname varchar(50),
chu smallint default 0,
writeday datetime
);

이미지 업로드


이미지 업로드 할 save 폴더 생성 해두기

폼에 enctype 설정 enctype="multipart/form-data"

camera glyphicon 클릭 시 파일 선택 및 이미지 미리보기

<script>
	$(function() {
		$("span.camera").click(function() {
			$("#photo").trigger("click"); //이벤트 강제호출
		})
	})

	//이미지 미리보기
	function readURL(input) {
		if (input.files && input.files[0]) {
			var reader = new FileReader();
			reader.onload = function(e) {
				$("#showimg").attr("src", e.target.result);
			}
			reader.readAsDataURL(input.files[0]);
		}
	}
</script>
<!-- 이미지 미리보기 할 위치 -->
		<img id="showimg" style="position: absolute; left: 700px; top: 80px; max-width: 200px;">
		<form action="guest/addaction.jsp;" method="post" enctype="multipart/form-data">
			<table style="width: 600px">
				<caption>
					<b>방명록 등록</b> <span class="glyphicon glyphicon-camera camera"></span>
					<input type="file" name="photo" id="photo" style="visibility: hidden" onchange="readURL(this)">
				</caption>
...

삭제 시 업로드한 이미지도 같이 삭제