728x90
list.jsp(기능부분만 발췌)
<table width=1100 border=1 align="center">
<tr>
<td width =80 class="td_title">No</td>
<td width = 560 class="td_title">영상</td>
<td width = 100 class="td_title">운동명</td>
<td width = 200 class="td_title">운동설명</td>
<td width=60 class="td_title">작성자</td>
<td width = 60 class="td_title">조회수</td>
</tr>
</table>
<table width=1100 border=1 >
<%
int numbering = total_record - (page_now -1) * num_per_page;
int num = 0;
while(rs.next()){
int uid = rs.getInt("uid");
String subject = rs.getString("subject");
String tb_video = rs.getString("tb_video");
String comment_health = rs.getString("comment_health");
String name = rs.getString("name");
String id = rs.getString("id");
int com_count = rs.getInt("com_count");
String signdate = rs.getString("signdate").substring(0,10);
int ref = rs.getInt("ref");
String delete_id = rs.getString("delete_id");
if(comment_health.length() >60){
comment_health = comment_health.substring(0,60)+"...";
}
%>
<tr>
<td width = 80 align=center style="text-align: center">
<b><%=numbering %></b>
</td>
<td width = 560><iframe width="560" height="315" src="https://www.youtube.com/embed/<%=tb_video.substring(32,43) %>" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></td>
<td width = 100><a href = "view.jsp?code=<%=code%>&uid=<%=uid%>"><h2><%=subject %><div style="color: blue">[<%=com_count %>]</div></h2></a></td>
<td width = 200><%=comment_health %></td>
<td width = 70 style="text-align: center"><%=name%></td>
<td width = 60><%=ref %></td>
</tr>
<% numbering --;
}
rs.close();
stmt.close();
con.close();
if(total_record == 0){
out.print("<tr><td colspan=5 align=center height=100>작성하신 글이 없습니다. </td></tr>");
}
%>
</table>
write.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file = "/include/header2.jsp" %>
<%
String code = request.getParameter("code");
%>
<style>
body{
background-color: white;
}
</style>
<script>
function write_go(){
if(!subject.value){
alert("제목을 입력하세요")
subject.focus();
return false;
}
if(!comment_health.value){
alert("내용을 입력하세요")
comment.focus();
return false;
}
document.submit();
}
</script>
<table height=100>
<tr>
<td></td>
</tr>
</table>
<form action="insert.jsp" method="get" onsubmit="return write_go()" enctype="multipart/form-data">
<input type="hidden" name="code" value="<%=code%>">
<table width=1100 align=center border=1>
<tr>
<th>영상 주소를 입력해주세요<br><b style="color: red">유투브 영상만 가능하며 https://www.youtube.com부터 전부 입력하셔야 합니다.</b></th>
</tr>
<tr>
<td>
<input id="tb_video" name="tb_video" style="width:99%;height:120px">
</td>
</tr>
<tr>
<th>운동명</th>
</tr>
<tr>
<td>
<input id="subject" name="subject" style="width:99%;height:120px">
</td>
</tr>
<tr>
<th>운동설명</th>
</tr>
<tr>
<td><textarea id = "comment_health" name = "comment_health" style="width:99%;height:120px"></textarea></td>
</tr>
</table>
<p></p>
<table width=1100 >
<tr>
<td align="left" ><input type="button" onclick = "list.jsp?code=<%=code %>" value="목록" style="width:100px;height:30px"></a></b></td>
<td align="right"><button style="width:100px;height:30px">글쓰기</button></td>
</tr>
</table>
</form>
<p></p>
유투브에서 주소 뒤에 고유값 부분 데이터베이스에 저장(insert.jsp)
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.Enumeration"%>
<%@page import="com.oreilly.servlet.*"%>
<%@page import="com.oreilly.servlet.multipart.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file = "/include/header.jsp" %>
<%
request.setCharacterEncoding("utf-8");
String code = request.getParameter("code");
String subject = request.getParameter("subject");
String tb_video = request.getParameter("tb_video");
//out.print(tb_video);
String comment_health = request.getParameter("comment_health");
String sql_fid = "select max(fid) as fid_max from "+code+"";
Connection con_count = DriverManager.getConnection(url, user, password);
Statement stmt_count = con_count.createStatement();
ResultSet rs_count = stmt_count.executeQuery(sql_fid);
int fid = 1;
if(rs_count.next()){
if(rs_count.getInt("fid_max") > 0){
fid = rs_count.getInt("fid_max") + 1;
}else{
fid = 1;
}
}
rs_count.close();
stmt_count.close();
con_count.close();
Date today = new Date();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String signdate = sd.format(today);
String sql = "insert into "+code+" (id,name,tb_video,subject,comment_health,signdate,fid,thread) values ('"+session_id+"','"+session_name+"','"+tb_video+"','"+subject+"','"+comment_health+"','"+signdate+"',"+fid+",'A')";
out.print(sql);
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
stmt.executeUpdate(sql);
%>
<script>
location.href = "list.jsp?code=<%=code%>";
</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/header2.jsp" %>
<%
//int uid = Integer.parseInt(request.getParameter("uid"));
String code = request.getParameter("code");
String uid = request.getParameter("uid");
String sql_ref = "update "+code+" set ref=ref+1 where uid="+uid+"";
Connection con_ref = DriverManager.getConnection(url, user, password);
Statement stmt_ref = con_ref.createStatement();
stmt_ref.executeUpdate(sql_ref);
stmt_ref.close();
con_ref.close();
String sql = "select * from "+code+" where uid="+uid+"";
Connection con = DriverManager.getConnection(url, user, password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
String id = "";
if(rs.next()){
id = rs.getString("id");
String comment_health = rs.getString("comment_health");
String tb_video = rs.getString("tb_video");
String subject = rs.getString("subject");
//tb_comment 개행처리
pageContext.setAttribute("cmt2", comment_health);
pageContext.setAttribute("LF", "\n");
%>
<table width=1100 align="center" border=0>
<tr>
<td align="right">
글쓴이 : <%=rs.getString("name") %>
조회수 : <%=rs.getInt("ref") %>
</td>
</tr>
</table>
<table width=1100 border=1>
<tr>
<th>영상</th>
<td><iframe width="560" height="315" src="https://www.youtube.com/embed/<%=tb_video.substring(32,43) %>" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe></td>
</tr>
<tr>
<th>운동명</th>
<td>
<input id="subject" name="subject" style="width:99%" value = <%=subject %>>
</td>
</tr>
<tr>
<th>운동설명</th>
<td><textarea id = "comment_health" name = "comment_health" style="width:99%;height:120px"><%=comment_health %></textarea></td>
</tr>
</table>
<%}
rs.close();
stmt.close();
con.close();
%>
<table>
<tr>
<td height=15></td>
</tr>
</table>
<%if(session_name != null && session_name != ""){ %>
<form action = "comment_insert.jsp" method = "post">
<input type="hidden" name = "tb_table" value = "<%=code %>">
<input type = "hidden" name = "tb_uid" value = "<%=uid %>">
<table width = 1100 align="center" border=0>
<tr>
<td colspan=3 align="left">댓글</td>
</tr>
<tr>
<td width=300><%=session_name %></td>
<td width=700><input name = "tb_comment" style="width:98%;height:20px"></td>
<td align=right width=100 ><button style="width:50px;height:30px">작성</button></td>
</tr>
</table>
</form>
<%} %>
<%
String sql_comment = "select * from comment where tb_table = '"+code+"' and tb_uid = "+uid+" order by uid desc";
Connection con_comment = DriverManager.getConnection(url, user, password);
Statement stmt_comment = con_comment.createStatement();
ResultSet rs_comment = stmt_comment.executeQuery(sql_comment);
%>
<table>
<tr>
<td height=15></td>
</tr>
</table>
<table width= 1100 align="center" border=0>
<%
Date today = new Date();
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
String signdate = sd.format(today);
while(rs_comment.next()){
int c_uid = rs_comment.getInt("uid");
String t_id = rs_comment.getString("tb_id");
%>
<tr>
<td width=300><%=rs_comment.getString("tb_name") %> | <%=signdate %></td>
<td width=700><%=rs_comment.getString("tb_comment") %></td>
<%if(session_id != null && session_level.equals("10")){ %>
<td width=100 align=right><a href = "comment_del.jsp?code=<%=code %>&uid=<%=uid%>&c_uid=<%=c_uid%>"><img src ="img/comment_del.gif" width=50%></a></td>
<%}else if(session_id != null && session_id.equals(t_id)){ %>
<td width=100 align=right><a href = "comment_del.jsp?code=<%=code %>&uid=<%=uid%>&c_uid=<%=c_uid%>"><img src ="img/comment_del.gif" width=50%></a></td>
<%}else{ %>
<td></td>
<%} %>
</tr>
<%
}
rs_comment.close();
stmt_comment.close();
con_comment.close();
%>
</table>
<br>
<table width = 1100 align="center" border=0>
<tr>
<td><a href = "list.jsp?code=<%=code%>">[목록]</a></td>
<%if(session_id !=null && session_level.equals("10")){ %>
<td align="right">
<a href = "modify.jsp?code=<%=code%>&uid=<%=uid %>">[수정]</a>
<a href = "delete.jsp?code=<%=code%>&uid=<%=uid %>">[삭제]</a>
</td>
<%}else if(session_id !=null && session_id.equals(id)){ %>
<td align="right">
<a href = "modify.jsp?code=<%=code%>&uid=<%=uid %>">[수정]</a>
<a href = "delete.jsp?code=<%=code%>&uid=<%=uid %>">[삭제]</a>
</td>
<%}else{%>
<td></td>
<%} %>
</tr>
</table>
<p></p>
<%@include file="/include/footer2.jsp" %>
'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 |