-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.jsp
143 lines (136 loc) · 4.74 KB
/
view.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import= "java.io.PrintWriter" %>
<%@ page import= "bbs.Bbs" %>
<%@ page import= "bbs.BbsDAO" %>
<%@ page import= "java.io.File" %>
<%@ page import= "java.lang.reflect.Field" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width", initial-scale="1">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/custom.css">
<title>JSP 게시판 웹사이트 </title>
</head>
<body>
<%
String userID = null;
if(session.getAttribute("userID") != null); {
userID = (String)session.getAttribute("userID");
}
int bbsID = 0;
if (request.getParameter("bbsID") != null) {
bbsID = Integer.parseInt(request.getParameter("bbsID"));
}
if(bbsID == 0) {
PrintWriter script = response.getWriter();
script.println("<script>");
script.println("alert('유효하지 않은 글 입니다.')");
script.println("locaton.href = 'bbs.jsp'");
script.println("</script>");
}
Bbs bbs = new BbsDAO().getBbs(bbsID);
System.out.println("title : " + bbs.getBbsTitle());
System.out.println("userId : " + bbs.getUserID());
System.out.println("bbsDate : " + bbs.getBbsDate());
%>
<nav class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
aria-expanded="false">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="main.jsp">방명록</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="main.jsp">메인</a></li>
<li class="active"><a href="bbs.jsp">게시판</a></li>
</ul>
<%
if(userID == null) {
%>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">로그인/가입<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="login.jsp">로그인</a></li>
<li><a href="join.jsp">회원가입</a></li>
</ul>
</li>
</ul>
<%
} else {
%>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">회원관리<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="logoutAction.jsp">로그아웃</a></li>
</ul>
</li>
</ul>
<%
}
%>
</div>
</nav>
<div class="container">
<div class="row">
<table class="table table-striped" style="text-align: center; border:1px solid #dddddd">
<thead>
<tr>
<th colspan="3" style= "background-color: #eeeeee; text-align: center;">게시판 글보기</th>
</tr>
</thead>
<tbody>
<tr>
<td style="width: 20%;">제목</td>
<td colspan="2"><%=bbs.getBbsTitle()%></td>
</tr>
<tr>
<td>작성자</td>
<td colspan="2"><%=bbs.getUserID()%></td>
</tr>
<tr>
<td>작성일자</td>
<td colspan="2"><%=bbs.getBbsDate().substring(0,11) +bbs.getBbsDate().substring(11,13) + "시" + bbs.getBbsDate().substring(14,16) + "분"%></td>
</tr>
<tr>
<td>내용</td>
<td colspan="2" style="min-height: 200px; text-align:left;"><%=bbs.getBbsContent().replaceAll(" "," ").replaceAll("<","<").replaceAll(">",">").replaceAll("\n","<br>") %></td>
</tr>
</tbody>
</table>
<%
String directory = application.getRealPath("/upload/" +bbsID+"/");
String files[] = new File(directory).list();
for(String file : files){
out.write("<a href=\"" + request.getContextPath() + "/downloadAction?bbsID=" +bbsID+"&file="
+ java.net.URLEncoder.encode(file, "UTF-8") +"\">"+file+ "</a><br>");
}
%>
<a href="bbs.jsp" class="btn btn-primary">목록</a>
<%
if(userID != null && userID.equals(bbs.getUserID())) {
%>
<a href="update.jsp?bbsID=<%= bbsID %>" class="btn btn-primary">수정</a>
<a onclick= "return confirm('정말로 삭제하시겠습니까?')" href="deleteAction.jsp?bbsID=<%= bbsID %>" class="btn btn-primary">삭제</a>
<%
}
%>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>