728x90
데이터베이스 구성
쪽지 목록(list.jsp)
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.net.ConnectException"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String session_id = (String)session.getAttribute("id");
String session_name = (String)session.getAttribute("name");
String session_level = (String)session.getAttribute("level");
String send_option = request.getParameter("send_option");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>쪽지함</title>
<style>
@font-face {
font-family: 'dalla';
src: url('/font/dalla_Light.ttf') format('truetype');
}
body{
background-color: black;
color: white;
}
a{
color: white;
text-decoration: none;
}
.header_font{
color:white;
font-family: 'dalla';
}
</style>
</head>
<%
request.setCharacterEncoding("utf-8");
String field = "";
String search = "";
if(request.getParameter("search") != null){
field = request.getParameter("field");
search = request.getParameter("search");
}
String sql_receive="select * from message where d_id='"+session_id+"' and other_delete='1' order by uid desc";
if(request.getParameter("search") != null){
sql_receive = "select * from message where d_id='"+session_id+"' and other_delete='1' and "+field+" like '%"+search+"%' order by uid desc";
}
Connection con_receive = DriverManager.getConnection(url, user, password);
Statement stmt_receive = con_receive.createStatement();
ResultSet rs_receive = stmt_receive.executeQuery(sql_receive);
String sql_send="select * from message where s_id='"+session_id+"' and my_delete='1' order by uid desc";
if(request.getParameter("search") != null){
sql_send = "select * from message where s_id ='"+session_id+"' and my_delete='1' and "+field+" like '%"+search+"%' order by uid desc";
}
Connection con_send = DriverManager.getConnection(url, user, password);
Statement stmt_send = con_send.createStatement();
ResultSet rs_send = stmt_send.executeQuery(sql_send);
String sql_count_receive = "select count(*) from message where d_id='"+session_id+"' and other_delete='1' order by uid desc";
Connection con_count_receive = DriverManager.getConnection(url, user, password);
Statement stmt_count_receive = con_count_receive.createStatement();
ResultSet rs_count_receive = stmt_count_receive.executeQuery(sql_count_receive);
String sql_count_send = "select count(*) from message where s_id='"+session_id+"' and my_delete='1' order by uid desc";
Connection con_count_send = DriverManager.getConnection(url, user, password);
Statement stmt_count_send = con_count_send.createStatement();
ResultSet rs_count_send = stmt_count_send.executeQuery(sql_count_send);
String sql_count_nonview = "select count(*) from message where d_id='"+session_id+"' and other_delete='1' and d_date='' order by uid desc";
Connection con_count_nonview = DriverManager.getConnection(url, user, password);
Statement stmt_count_nonview = con_count_nonview.createStatement();
ResultSet rs_count_nonview = stmt_count_nonview.executeQuery(sql_count_nonview);
int total_record_recieve = 0;
if(rs_count_receive.next()){
total_record_recieve = rs_count_receive.getInt("count(*)");
}
rs_count_receive.close();
stmt_count_receive.close();
con_count_receive.close();
int total_record_send = 0;
if(rs_count_send.next()){
total_record_send = rs_count_send.getInt("count(*)");
}
rs_count_send.close();
stmt_count_send.close();
con_count_send.close();
int total_record_nonview = 0;
if(rs_count_nonview.next()){
total_record_nonview = rs_count_nonview.getInt("count(*)");
}
rs_count_nonview.close();
stmt_count_nonview.close();
con_count_nonview.close();
int page_now = 1;
if(request.getParameter("page_now") !=null){
page_now = Integer.parseInt(request.getParameter("page_now"));
}else{
page_now = 1;
}
int num_per_page = 8;
int page_per_block = 5;
int total_page_accept = 0;
int total_page_send = 0;
int first = 0;
total_page_accept = (int)Math.ceil(total_record_recieve / (double)num_per_page);
total_page_send = (int)Math.ceil(total_record_send / (double)num_per_page);
first = num_per_page * (page_now - 1);
String sql_view = "select count(*) from message where d_date='' and d_id='"+session_id+"'";
Connection con_view = DriverManager.getConnection(url, user, password);
Statement stmt_view = con_view.createStatement();
ResultSet rs_view = stmt_view.executeQuery(sql_view);
String sql_recieve_count = "select count(*) from message where d_id='"+session_id+"' and other_delete='1'";
Connection con_recieve_count = DriverManager.getConnection(url, user, password);
Statement stmt_recieve_count = con_recieve_count.createStatement();
ResultSet rs_recieve_count = stmt_recieve_count.executeQuery(sql_recieve_count);
String sql_send_count= "select count(*) from message where s_id='"+session_id+"' and my_delete='1'";
Connection con_send_count = DriverManager.getConnect
쪽지 쓰기(write.jsp)
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
request.setCharacterEncoding("utf-8");
String session_id = (String)session.getAttribute("id");
String session_name = (String)session.getAttribute("name");
String session_level = (String)session.getAttribute("level");
String sql = "select * from member where delete_id='n' and id !='"+session_id+"'";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
String sql_view = "select count(*) from message where d_date='' and d_id='"+session_id+"'";
Connection con_view = DriverManager.getConnection(url, user, password);
Statement stmt_view = con_view.createStatement();
ResultSet rs_view = stmt_view.executeQuery(sql_view);
String sql_recieve_count = "select count(*) from message where d_id='"+session_id+"' and other_delete='1'";
Connection con_recieve_count = DriverManager.getConnection(url, user, password);
Statement stmt_recieve_count = con_recieve_count.createStatement();
ResultSet rs_recieve_count = stmt_recieve_count.executeQuery(sql_recieve_count);
String sql_send_count= "select count(*) from message where s_id='"+session_id+"' and my_delete='1'";
Connection con_send_count = DriverManager.getConnection(url, user, password);
Statement stmt_send_count = con_send_count.createStatement();
ResultSet rs_send_count = stmt_send_count.executeQuery(sql_send_count);
String send_count = "";
while(rs_send_count.next()){
send_count = rs_send_count.getString("count(*)");
}
String recieve_count = "";
while(rs_recieve_count.next()){
recieve_count = rs_recieve_count.getString("count(*)");
}
String nonview = "";
while(rs_view.next()){
nonview = rs_view.getString("count(*)");
}
%>
<style>
@font-face {
font-family: 'dalla';
src: url('/font/dalla_Light.ttf') format('truetype');
}
body{
background-color: black;
color: white;
}
a{
color: white;
text-decoration: none;
}
.header_font{
color:white;
font-family: 'dalla';
}
.send_img{
background-image: url('/img/send.png');
background-repeat: no-repeat;
background-size: cover;
}
</style>
<script>
function write_go(){
location.href = "write.jsp";
}
function selfClose(){
self.close();
}
function send_go(){
if(d_id.value==""){
alert("받는사람을 입력해주세요");
d_id.focus();
return false;
}
if(d_id.value==<%=session_id%>){
alert("자기한테 쪽지를 보낼 수 없습니다.");
d_id.focus();
return false;
}
document.submit();
}
</script>
<center>
<table>
<tr>
<td height=30></td>
</tr>
</table>
<table border=0>
<tr>
<td style="vertical-align: top">
<table width=200 border=0 >
<tr>
<td style="vertical-align: top"><input type="button" onclick="write_go()" value="쪽지쓰기" style="width:80%;height:40px" ></td>
</tr>
<tr>
<td height=50></td>
</tr>
<tr>
<td class="header_font"><a href = "list.jsp?send_option=1">받은 쪽지함</a></td>
</tr>
<tr>
<td class="header_font"> <a href="list.jsp?send_option=1">받은 쪽지 수[<%=recieve_count %>]</a></td>
</tr>
<tr>
<td class="header_font"> <a href="list.jsp?send_option=3">안읽은 쪽지 수[<%=nonview %>]</a></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td class="header_font"><a href = "list.jsp?send_option=2">보낸 쪽지함</a></td>
</tr>
<tr>
<td class="header_font"> <a href ="list.jsp?send_option=2">보낸 쪽지 수[<%=send_count %>]</a></td>
</tr>
</table>
</td>
<td width=50 ></td>
<form action="insert.jsp" method="get" onsubmit="return send_go()">
<td style="vertical-align: top">
<table>
<tr>
<td><h1>쪽지 쓰기</h1></td>
</tr>
<tr>
<td><button style="width:100px;height:30px" class="send_img"></button></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td>
<%if(request.getParameter("d_id") != null){%>
받는 사람 : <input id="d_id" name="d_id" value ="<%=request.getParameter("d_id")%>">
<select onchange="d_id.value=this.value">
<option id="d_id2" name="d_id2" value="">==회원목록==</option>
<%while(rs.next()){ %>
<option id="d_id2" name="d_id2" value="<%=rs.getString("id") %>">아이디 : <%=rs.getString("id") %> 이름 : <%=rs.getString("name") %></option>
<%}
rs.close();
stmt.close();
con.close();
}else{%>
받는 사람 : <input id="d_id" name="d_id" >
<select onchange="d_id.value=this.value">
<option id="d_id2" name="d_id2" value="">==회원목록==</option>
<%while(rs.next()){ %>
<option id="d_id2" name="d_id2" value="<%=rs.getString("id") %>">아이디 : <%=rs.getString("id") %> 이름 : <%=rs.getString("name") %></option>
<% }
}%>
</select>
</td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td><textarea id="comment" name="comment" style="width:500px;height:400px"></textarea></td>
</tr>
</table>
<table width=800>
<tr>
<td style="text-align: left">
<a href ="list.jsp?send_option=1">[목록]</a>
</td>
<td style="text-align: right"><a href ="javascript:selfClose()">[닫기]</a></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</center>
쪽지 작성내용 데이터베이스 저장(insert.jsp)
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String session_id = (String)session.getAttribute("id");
String session_name = (String)session.getAttribute("name");
String session_level = (String)session.getAttribute("level");
request.setCharacterEncoding("utf-8");
String d_id= request.getParameter("d_id");
String comment = request.getParameter("comment");
Date today = new Date();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String signdate = sd.format(today);
String sql_check ="select * from member where id='"+d_id+"'";
Connection con_check = DriverManager.getConnection(url, user, password);
Statement stmt_check = con_check.createStatement();
ResultSet rs_check = stmt_check.executeQuery(sql_check);
String id= "";
String delete_id = "";
while(rs_check.next()){
delete_id = rs_check.getString("delete_id");
id=rs_check.getString("id");
}
if(id.equals("")){%>
<script>
alert("존재하지않는 회원입니다.");
location.href="write.jsp";
</script>
<%}else{
if(delete_id.equals("y")){%>
<script>
alert("탈퇴한 회원입니다.");
location.href="write.jsp";
</script>
<%}else{
String sql = "insert into message (s_id,d_id,comment,s_date) values ('"+session_id+"','"+d_id+"','"+comment+"','"+signdate+"')";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
}
} %>
<script>
location.href = "list.jsp?send_option=2"
</script>
쪽지 보기(view.jsp)
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String session_id = (String)session.getAttribute("id");
String session_name = (String)session.getAttribute("name");
String session_level = (String)session.getAttribute("level");
String uid = request.getParameter("uid");
String send_option = request.getParameter("send_option");
String sql_receive ="select * from message where d_id='"+session_id+"' and uid="+uid+"";
Connection con_receive = DriverManager.getConnection(url, user, password);
Statement stmt_receive = con_receive.createStatement();
ResultSet rs_receive = stmt_receive.executeQuery(sql_receive);
String sql_send ="select * from message where s_id='"+session_id+"' and uid="+uid+"";
Connection con_send= DriverManager.getConnection(url, user, password);
Statement stmt_send = con_send.createStatement();
ResultSet rs_send = stmt_send.executeQuery(sql_send);
String sql_view = "select count(*) from message where d_date='' and d_id='"+session_id+"'";
Connection con_view = DriverManager.getConnection(url, user, password);
Statement stmt_view = con_view.createStatement();
ResultSet rs_view = stmt_view.executeQuery(sql_view);
String sql_recieve_count = "select count(*) from message where d_id='"+session_id+"' and other_delete='1'";
Connection con_recieve_count = DriverManager.getConnection(url, user, password);
Statement stmt_recieve_count = con_recieve_count.createStatement();
ResultSet rs_recieve_count = stmt_recieve_count.executeQuery(sql_recieve_count);
String sql_send_count= "select count(*) from message where s_id='"+session_id+"' and my_delete='1'";
Connection con_send_count = DriverManager.getConnection(url, user, password);
Statement stmt_send_count = con_send_count.createStatement();
ResultSet rs_send_count = stmt_send_count.executeQuery(sql_send_count);
String send_count = "";
while(rs_send_count.next()){
send_count = rs_send_count.getString("count(*)");
}
String recieve_count = "";
while(rs_recieve_count.next()){
recieve_count = rs_recieve_count.getString("count(*)");
}
String nonview = "";
while(rs_view.next()){
nonview = rs_view.getString("count(*)");
}
%>
<style>
@font-face {
font-family: 'dalla';
src: url('/font/dalla_Light.ttf') format('truetype');
}
body{
background-color: black;
color: white;
}
a{
color: white;
text-decoration: none;
}
.header_font{
color:white;
font-family: 'dalla';
}
</style>
<script>
if(self.name != 'reload'){
self.name = 'reload';
self.location.reload(true);
}else{
self.name = '';
}
opener.document.location.reload();
function write_go(){
location.href = "write.jsp";
}
function selfClose(){
self.close();
}
function delete_go_sendoption1(){
result = confirm("정말 삭제하시겠습니까?");
if(result == true){
location.href="delete.jsp?send_option=1&uid=<%=uid%>";
}else{
return false;
}
}
function delete_go_sendoption2(){
result = confirm("정말 삭제하시겠습니까?");
if(result == true){
location.href="delete.jsp?send_option=2&uid=<%=uid%>";
}else{
return false;
}
}
</script>
<table>
<tr>
<td height=30></td>
</tr>
</table>
<center>
<table border=0>
<tr>
<td style="vertical-align: top">
<table width=200 border=0>
<tr>
<td><input type="button" onclick="write_go()" value="쪽지쓰기" style="width:80%;height:40px" ></td>
</tr>
<tr>
<td height=50></td>
</tr>
<tr>
<td class="header_font"><a href = "list.jsp?send_option=1">받은 쪽지함</a></td>
</tr>
<tr>
<td class="header_font"> <a href="list.jsp?send_option=1">받은 쪽지 수[<%=recieve_count %>]</a></td>
</tr>
<tr>
<td class="header_font"> <a href="list.jsp?send_option=3">안읽은 쪽지 수[<%=nonview %>]</a></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td class="header_font"><a href = "list.jsp?send_option=2">보낸 쪽지함</a></td>
</tr>
<tr>
<td class="header_font"> <a href ="list.jsp?send_option=2">보낸 쪽지 수[<%=send_count %>]</a></td>
</tr>
</table>
</td>
<td width=50 ></td>
<td style="vertical-align: top">
<table width=800>
<%
String s_id = "";
String d_id = "";
String comment ="";
String s_date="";
String d_date="";
if(rs_receive.next()){
s_id =rs_receive.getString("s_id");
d_id = rs_receive.getString("d_id");
comment =rs_receive.getString("comment");
s_date = rs_receive.getString("s_date");
d_date = rs_receive.getString("d_date");
if(d_date.equals("")){
Date today = new Date();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String signdate = sd.format(today);
String sql_date = "update message set d_date='"+signdate+"' where uid="+uid+"";
Connection con_date = DriverManager.getConnection(url, user, password);
Statement stmt_date = con_date.createStatement();
stmt_date.executeUpdate(sql_date);
}
%>
<tr>
<td>보낸사람 : <%=s_id %></td>
<td style="text-align: right"><a href ="reply.jsp?uid=<%=uid%>">답장하기</a></td>
</tr>
<tr>
<td colspan=2 height=30></td>
</tr>
<tr>
<td colspan=2>보낸 시간 :<%=s_date %></td>
</tr>
<tr>
<td colspan=2>받은 시간 :<%=d_date %></td>
</tr>
<tr>
<td height=30 colspan=2></td>
</tr>
<tr>
<td colspan=2><textarea style="width:500px;height:400px"><%=comment %></textarea></td>
</tr>
<%}
rs_receive.close();
stmt_receive.close();
con_receive.close();
if(rs_send.next()){
d_id = rs_send.getString("d_id");
comment =rs_send.getString("comment");
s_date = rs_send.getString("s_date");
d_date=rs_send.getString("d_date");
%>
<tr>
<td>받는사람 : <%=d_id %></td>
<td style="text-align: right"></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td>보낸 시간 :<%=s_date %></td>
</tr>
<tr>
<td>읽은 시간 :<%=d_date %></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td><textarea style="width:100%;height:400px"><%=comment %></textarea></td>
</tr>
<%}
rs_send.close();
stmt_send.close();
con_send.close();
%>
</table>
<table width=800>
<tr>
<td style="text-align: left">
<%if(send_option.equals("1")){ %>
<a href ="list.jsp?send_option=1">[목록]</a>
<a href= "javascript:delete_go_sendoption1()">[삭제]</a>
<%}else{ %>
<a href ="list.jsp?send_option=2">[목록]</a>
<a href= "javascript:delete_go_sendoption2()">[삭제]</a>
<%} %>
</td>
<td style="text-align: right"><a href ="javascript:selfClose()">[닫기]</a></td>
</tr>
</table>
</td>
</tr>
</table>
쪽지 답변(reply.jsp)
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String session_id = (String)session.getAttribute("id");
String session_name = (String)session.getAttribute("name");
String session_level = (String)session.getAttribute("level");
String uid = request.getParameter("uid");
String sql = "select * from message where uid="+uid+"";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
String sql_view = "select count(*) from message where d_date='' and d_id='"+session_id+"'";
Connection con_view = DriverManager.getConnection(url, user, password);
Statement stmt_view = con_view.createStatement();
ResultSet rs_view = stmt_view.executeQuery(sql_view);
String sql_recieve_count = "select count(*) from message where d_id='"+session_id+"' and other_delete='1'";
Connection con_recieve_count = DriverManager.getConnection(url, user, password);
Statement stmt_recieve_count = con_recieve_count.createStatement();
ResultSet rs_recieve_count = stmt_recieve_count.executeQuery(sql_recieve_count);
String sql_send_count= "select count(*) from message where s_id='"+session_id+"' and my_delete='1'";
Connection con_send_count = DriverManager.getConnection(url, user, password);
Statement stmt_send_count = con_send_count.createStatement();
ResultSet rs_send_count = stmt_send_count.executeQuery(sql_send_count);
String send_count = "";
while(rs_send_count.next()){
send_count = rs_send_count.getString("count(*)");
}
rs_send_count.close();
stmt_send_count.close();
con_send_count.close();
String recieve_count = "";
while(rs_recieve_count.next()){
recieve_count = rs_recieve_count.getString("count(*)");
}
rs_recieve_count.close();
stmt_recieve_count.close();
con_recieve_count.close();
String nonview = "";
while(rs_view.next()){
nonview = rs_view.getString("count(*)");
}
rs_view.close();
stmt_view.close();
con_view.close();
%>
<style>
@font-face {
font-family: 'dalla';
src: url('/font/dalla_Light.ttf') format('truetype');
}
body{
background-color: black;
color: white;
}
a{
color: white;
text-decoration: none;
}
.header_font{
color:white;
font-family: 'dalla';
}
.send_img{
background-image: url('/img/send.png');
background-repeat: no-repeat;
background-size: cover;
}
</style>
<script>
function write_go(){
location.href = "write.jsp";
}
function selfClose(){
self.close();
}
function send_go(){
if(d_id.value==<%=session_id%>){
alert("자기한테 쪽지를 보낼 수 없습니다.");
d_id.focus();
return false;
}
document.submit();
}
</script>
<%
while(rs.next()){
String s_id = rs.getString("s_id");
String comment = rs.getString("comment");
%>
<center>
<table>
<tr>
<td height=30></td>
</tr>
</table>
<table border=0>
<tr>
<td style="vertical-align: top">
<table width=200 border=0 >
<tr>
<td style="vertical-align: top"><input type="button" onclick="write_go()" value="쪽지쓰기" style="width:80%;height:40px" ></td>
</tr>
<tr>
<td height=50></td>
</tr>
<tr>
<td class="header_font"><a href = "list.jsp?send_option=1">받은 쪽지함</a></td>
</tr>
<tr>
<td class="header_font"> 받은 쪽지 수[<%=recieve_count %>]</td>
</tr>
<tr>
<td class="header_font"> 안읽은 쪽지 수[<%=nonview %>]</td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td class="header_font"><a href = "list.jsp?send_option=2">보낸 쪽지함</a></td>
</tr>
<tr>
<td class="header_font"> 보낸 쪽지 수[<%=send_count %>]</td>
</tr>
</table>
</td>
<td width=50 ></td>
<form action="reply_insert.jsp" method="get" onsubmit="return send_go()">
<td style="vertical-align: top">
<table>
<tr>
<td><h1>쪽지 쓰기</h1></td>
</tr>
<tr>
<td><button style="width:100px;height:30px" class="send_img"></button></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td>받는 사람 : <input id="d_id" name="d_id" value="<%=s_id%>"></td>
</tr>
<tr>
<td height=30></td>
</tr>
<tr>
<td><textarea id="comment" name="comment" style="width:500px;height:400px">RE:<%=comment %></textarea></td>
</tr>
</table>
<table width=800>
<tr>
<td style="text-align: left">
<a href ="list.jsp?send_option=1">[목록]</a>
</td>
<td style="text-align: right"><a href ="javascript:selfClose()">[닫기]</a></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</center>
<%}
rs.close();
stmt.close();
con.close();
%>
쪽지 답장 데이터베이스에 저장(reply_insert.jsp)
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String session_id = (String)session.getAttribute("id");
String session_name = (String)session.getAttribute("name");
String session_level = (String)session.getAttribute("level");
request.setCharacterEncoding("utf-8");
String d_id= request.getParameter("d_id");
String comment = request.getParameter("comment");
Date today = new Date();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String signdate = sd.format(today);
String sql = "insert into message (s_id,d_id,comment,s_date) values ('"+session_id+"','"+d_id+"','"+comment+"','"+signdate+"')";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
//out.print(sql);
%>
<script>
location.href = "list.jsp?send_option=2"
</script>
쪽지 삭제(delete.jsp) -데이터베이스에는 존재하며 보이지만 않게 구현하였다.
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String send_option = request.getParameter("send_option");
String uid = request.getParameter("uid");%>
<%
String sql="";
if(send_option.equals("2")){
sql = "update message set my_delete='2' where uid="+uid+"";
}else{
sql = "update message set other_delete='2' where uid="+uid+"";
}
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
//out.print(sql);
%>
<script>
location.href="list.jsp?send_option=<%=send_option%>"
</script>
쪽지 선택삭제 기능 구현(delete_select.jsp)
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@include file = "/include/db.jsp" %>
<%
String ids = request.getParameter("uids");
String send_option = request.getParameter("send_option");
//out.print(ids);
String[] uid_ch = ids.split(",");
String sql="";
if(send_option.equals("2")){
for(int i=0;i<uid_ch.length;i++){
sql = "update message set my_delete='2' where uid = '"+uid_ch[i]+"'";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
}
}else{
for(int i=0;i<uid_ch.length;i++){
sql = "update message set other_delete='2' where uid = '"+uid_ch[i]+"'";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
}
}
//out.print(sql);
%>
<script>
location.href="list.jsp?send_option=<%=send_option%>";
</script>
'Tools & Functions > Project 기능들' 카테고리의 다른 글
[JSP] 메일 인증 기능 구현 (0) | 2024.05.19 |
---|---|
[JSP] 댓글 기능 구현 (0) | 2024.05.19 |
[JSP] 영상 업로드 기능구현 (0) | 2024.05.19 |
[JSP] 선택삭제 기능 구현(체크박스) (0) | 2024.05.19 |
[JSP] 게시판 관련 기능 (0) | 2024.05.19 |