Advertisement
hyunjeong

Untitled

Aug 29th, 2019
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.84 KB | None | 0 0
  1. ★ bbs.jsp
  2. <%@ page language="java" contentType="text/html; charset=UTF-8"
  3. pageEncoding="UTF-8"%>
  4. <%@ page import = "java.io.PrintWriter" %>
  5. <%@ page import = "bbs.BbsDAO" %>
  6. <%@ page import = "bbs.Bbs" %>
  7. <%@ page import = "java.util.ArrayList" %>
  8. <html>
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  11. <title>JSP 게시판 웹사이트</title>
  12. <link rel="stylesheet" href="css/bootstrap.css">
  13. <style>
  14. a, a:hover {color:#000; text-decoration:none;}
  15. </style>
  16. </head>
  17. <body>
  18. <%
  19. String userId = null;
  20. if(session.getAttribute("userId") != null ) {
  21. userId = (String) session.getAttribute("userId");
  22. }
  23.  
  24. int pageNumber =1;
  25. if (request.getParameter("pageNumber")!= null) {
  26. pageNumber = Integer.parseInt(request.getParameter("pageNumber"));
  27. }
  28. %>
  29. <nav class= "navbar navbar-default">
  30. <div class="navbar-header">
  31. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
  32. data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  33. <span class="icon-bar"></span>
  34. <span class="icon-bar"></span>
  35. <span class="icon-bar"></span>
  36. </button>
  37. <a class="navbar-brand" href="login.jsp">JSP게시판 웹 사이트</a>
  38. </div>
  39. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  40. <ul class="nav navbar-nav">
  41. <li><a href="main.jsp">메인</a></li>
  42. <li class="active"><a href="bbs.jsp">게시판</a></li>
  43. </ul>
  44. <%
  45. if(userId == null) {
  46. %>
  47. <ul class="nav navbar-nav navbar-right">
  48. <li class="dropdown">
  49. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  50. aria-haspopup="true" aria-expanded="false" >
  51. 접속하기<span class=caret></span>
  52. </a>
  53. <ul class="dropdown-menu">
  54. <li><a href="login.jsp">로그인</a></li>
  55. <li><a href="join.jsp">회원가입</a></li>
  56. </ul>
  57. </li>
  58. </ul>
  59. <%
  60. } else {
  61. %>
  62. <ul class="nav navbar-nav navbar-right">
  63. <li class="dropdown">
  64. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  65. aria-haspopup="true" aria-expanded="false" >
  66. 회원관리<span class=caret></span>
  67. </a>
  68. <ul class="dropdown-menu">
  69.  
  70. <li><a href="logoutAction.jsp">로그아웃</a></li>
  71. </ul>
  72. </li>
  73. </ul>
  74. <%
  75. }
  76. %>
  77. </div>
  78. </nav>
  79. <div class="container">
  80. <div class="row">
  81. <table class="table table-striped" style="text-align:center; border:1px solid #dddddd" >
  82. <thead>
  83. <tr>
  84. <th style="background-color: #eeeeee; text-align:center;">번호</th>
  85. <th style="background-color: #eeeeee; text-align:center;">제목</th>
  86. <th style="background-color: #eeeeee; text-align:center;">작성자</th>
  87. <th style="background-color: #eeeeee; text-align:center;">작성일</th>
  88. </tr>
  89. </thead>
  90. <tbody>
  91. <%
  92. BbsDAO bbsDAO = new BbsDAO();
  93. ArrayList <Bbs> list = bbsDAO.getList(pageNumber);
  94. for (int i =0; i<list.size(); i++) {
  95. %>
  96. <tr>
  97. <td><%= list.get(i).getBbsId()%></td>
  98. <td><a href="view.jsp?bbsId=<%= list.get(i).getBbsId() %>"><%= list.get(i).getBbsTitle() %></a></td>
  99. <td><%= list.get(i).getUserId() %></td>
  100. <td><%= list.get(i).getBbsDate().substring(0,11)+
  101. list.get(i).getBbsDate().substring(11,13)+ "시 "+ list.get(i).getBbsDate().substring(14,16)+ "분" %></td>
  102. </tr>
  103. <%
  104. }
  105. %>
  106. </tbody>
  107. </table>
  108. <%
  109. if(pageNumber != 1) {
  110. %>
  111. <a href="bbs.jsp?pageNumber=<%=pageNumber-1 %>" class="btn btn-success btn-arrow-left">이전</a>
  112.  
  113. <%
  114. } if(bbsDAO.nextPage(pageNumber+1)) {
  115. %>
  116. <a href="bbs.jsp?pageNumber=<%=pageNumber+1 %>" class="btn btn-success btn-arrow-left">다음</a>
  117. <%
  118. }
  119. %>
  120. <a href="write.jsp" class="btn btn-primary pull-right">글쓰기</a>
  121. </div>
  122. </div>
  123. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  124. <script src="js/bootstrap.js"></script>
  125.  
  126. </body>
  127. </html>
  128.  
  129. ★ index.jsp
  130.  
  131. <%@ page language="java" contentType="text/html; charset=UTF-8"
  132. pageEncoding="UTF-8"%>
  133. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  134. <html>
  135. <head>
  136. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  137. <title>Insert title here</title>
  138. </head>
  139. <body>
  140. <script>
  141. location.href = 'main.jsp';
  142. </script>
  143. </body>
  144. </html>
  145.  
  146. ★join.jsp
  147.  
  148. <%@ page language="java" contentType="text/html; charset=UTF-8"
  149. pageEncoding="UTF-8"%>
  150. <html>
  151. <head>
  152. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  153. <title>JSP 게시판 웹사이트</title>
  154. <link rel="stylesheet" href="css/bootstrap.css">
  155. </head>
  156. <body>
  157. <nav class= "navbar navbar-default">
  158. <div class="navbar-header">
  159. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  160. <span class="icon-bar"></span>
  161. <span class="icon-bar"></span>
  162. <span class="icon-bar"></span>
  163. </button>
  164. <a class="navbar-brand" href="main.jsp">JSP게시판 웹 사이트</a>
  165. </div>
  166. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  167. <ul class="nav navbar-nav">
  168. <li><a href="main.jsp">메인</a></li>
  169. <li><a href="bbs.jsp">게시판</a></li>
  170. </ul>
  171. <ul class="nav navbar-nav navbar-right">
  172. <li class="dropdown">
  173. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  174. aria-haspopup="true" aria-expanded="false" >
  175. 접속하기<span class=caret></span>
  176. </a>
  177. <ul class="dropdown-menu">
  178. <li><a href="login.jsp">로그인</a></li>
  179. <li class="active"><a href="join.jsp">회원가입</a></li>
  180. </ul>
  181. </li>
  182. </ul>
  183. </div>
  184. </nav>
  185. <div class="container">
  186. <div class="col-lg-4"></div>
  187. <div class="col-lg-4">
  188. <div class="jumbotron" style="padding-top:20px;">
  189. <form method="post" action="joinAction.jsp">
  190. <h3 style="text-align-center;">회원가입 화면</h3>
  191. <div class="form-group">
  192. <input type="text" class="form-control" placeholder="아이디" name="userId" maxlength="20">
  193. </div>
  194. <div class="form-group">
  195. <input type="password" class="form-control" placeholder="비밀번호" name="userPassword" maxlength="20">
  196. </div>
  197. <div class="form-group">
  198. <input type="text" class="form-control" placeholder="이름" name="userName" maxlength="20">
  199. </div>
  200. <div class="form-group" style="text-align:center;">
  201. <div class="btn-group" data-toggle="buttons">
  202. <label class="btn btn-primary active">
  203. <input type="radio" name="userGender" autocomplete="off" value="남자" checked>남자
  204. </label>
  205. <label class="btn btn-primary active">
  206. <input type="radio" name="userGender" autocomplete="off" value="여자" checked>여자
  207. </label>
  208. </div>
  209. </div>
  210. <div class="form-group">
  211. <input type="Email" class="form-control" placeholder="이메일" name="userEmail" maxlength="20">
  212. </div>
  213. <input type="submit" class="btn btn-primary form-control" value="회원가입">
  214. </form>
  215. </div>
  216. </div>
  217. </div>
  218. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  219. <script src="js/bootstrap.js"></script>
  220. </body>
  221. </html>
  222.  
  223. ★ joinAction.jsp
  224.  
  225. <%@ page language="java" contentType="text/html; charset=UTF-8"
  226. pageEncoding="UTF-8"%>
  227. <%@ page import= "user.UserDAO" %>
  228. <%@ page import= "java.io.PrintWriter" %>
  229. <% request.setCharacterEncoding("UTF-8"); %>
  230. <jsp:useBean id="user" class="user.User" scope="page" />
  231. <jsp:setProperty name="user" property="userId" />
  232. <jsp:setProperty name="user" property="userPassword" />
  233. <jsp:setProperty name="user" property="userName" />
  234. <jsp:setProperty name="user" property="userGender" />
  235. <jsp:setProperty name="user" property="userEmail" />
  236. <html>
  237. <head>
  238. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  239. <title>jsp 게시판 웹사이트</title>
  240. </head>
  241. <body>
  242. <%
  243.  
  244. String userId = null;
  245.  
  246. if(session.getAttribute("userId") != null) {
  247. userId = (String) session.getAttribute("userId");
  248. }
  249.  
  250. if (userId != null ) {
  251. PrintWriter script = response.getWriter();
  252. script.println("<script>");
  253. script.println("alert('이미 로그인이 되어 있습니다. ')");
  254. script.println("location.href= main.jsp");
  255. script.println("</script>");
  256.  
  257. }
  258.  
  259. if (user.getUserId()==null || user.getUserPassword()==null || user.getUserName() ==null ||
  260. user.getUserGender()==null || user.getUserEmail()==null) {
  261. PrintWriter script = response.getWriter();
  262. script.println("<script>");
  263. script.println("alert('입력이 안 된 사항이 있습니다.')");
  264. script.println("history.back()");
  265. script.println("</script>");
  266. } else {
  267.  
  268.  
  269. UserDAO userDAO = new UserDAO();
  270. int result = userDAO.join(user);
  271.  
  272. if(result== - 1) {
  273. PrintWriter script = response.getWriter();
  274. script.println("<script>");
  275. script.println("alert('이미 존재하는 아이디입니다.')");
  276. script.println("history.back()");
  277. script.println("</script>");
  278. } else {
  279. PrintWriter script = response.getWriter();
  280. script.println("<script>");
  281. script.println("alert('비밀번호가 틀립니다.')");
  282. script.println("history.back()");
  283. script.println("</script>");
  284. }
  285. }
  286. %>
  287.  
  288. </body>
  289. </html>
  290.  
  291. ★ login.jsp
  292.  
  293. <%@ page language="java" contentType="text/html; charset=UTF-8"
  294. pageEncoding="UTF-8"%>
  295. <html>
  296. <head>
  297. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  298. <title>JSP 게시판 웹사이트</title>
  299. <link rel="stylesheet" href="css/bootstrap.css">
  300. </head>
  301. <body>
  302. <nav class= "navbar navbar-default">
  303. <div class="navbar-header">
  304. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  305. <span class="icon-bar"></span>
  306. <span class="icon-bar"></span>
  307. <span class="icon-bar"></span>
  308. </button>
  309. <a class="navbar-brand" href="login.jsp">JSP게시판 웹 사이트</a>
  310. </div>
  311. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  312. <ul class="nav navbar-nav">
  313. <li><a href="main.jsp">메인</a></li>
  314. <li><a href="bbs.jsp">게시판</a></li>
  315. </ul>
  316. <ul class="nav navbar-nav navbar-right">
  317. <li class="dropdown">
  318. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  319. aria-haspopup="true" aria-expanded="false" >
  320. 접속하기<span class=caret></span>
  321. </a>
  322. <ul class="dropdown-menu">
  323. <li class="active"><a href="login.jsp">로그인</a></li>
  324. <li><a href="join.jsp">회원가입</a></li>
  325. </ul>
  326. </li>
  327. </ul>
  328. </div>
  329. </nav>
  330. <div class="container">
  331. <div class="col-lg-4"></div>
  332. <div class="col-lg-4">
  333. <div class="jumbotron" style="padding-top:20px;">
  334. <form method="post" action="loginAction.jsp">
  335. <h3 style="text-align-center;">로그인 화면</h3>
  336. <div class="form-group">
  337. <input type="text" class="form-control" placeholder="아이디" name="userId" maxlength="20">
  338. </div>
  339. <div class="form-group">
  340. <input type="password" class="form-control" placeholder="비밀번호" name="userPassword" maxlength="20">
  341. </div>
  342. <input type="submit" class="btn btn-primary form-control" value="로그인">
  343. </form>
  344. </div>
  345. </div>
  346. </div>
  347. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  348. <script src="js/bootstrap.js"></script>
  349. </body>
  350. </html>
  351.  
  352. ★loginAction.jsp
  353.  
  354. <%@ page language="java" contentType="text/html; charset=UTF-8"
  355. pageEncoding="UTF-8"%>
  356. <%@ page import= "user.UserDAO" %>
  357. <%@ page import= "java.io.PrintWriter" %>
  358. <% request.setCharacterEncoding("UTF-8"); %>
  359. <jsp:useBean id="user" class="user.User" scope="page" />
  360. <jsp:setProperty name="user" property="userId" />
  361. <jsp:setProperty name="user" property="userPassword" />
  362. <html>
  363. <head>
  364. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  365. <title>jsp 게시판 웹사이트</title>
  366. </head>
  367. <body>
  368. <%
  369. if(user.getUserId() ==null || user.getUserPassword() == null) {
  370. PrintWriter script = response.getWriter();
  371. script.println("<script>");
  372. script.println("alert('입력되지 않은 사항이 있습니다.')");
  373. script.println("history.back()");
  374. script.println("</script>");
  375. }
  376. String userId = null;
  377.  
  378. if(session.getAttribute("userId") != null) {
  379. userId = (String) session.getAttribute("userId");
  380. }
  381.  
  382. UserDAO userDAO = new UserDAO();
  383. int result = userDAO.login(user.getUserId(), user.getUserPassword());
  384. if(result==1) {
  385. session.setAttribute("userId", user.getUserId());
  386. PrintWriter script = response.getWriter();
  387. script.println("<script>");
  388. script.println("alert('로그인 되었습니다. ')");
  389. script.println("location.href= 'main.jsp' ");
  390. script.println("</script>");
  391. } else if (result==0){
  392. PrintWriter script = response.getWriter();
  393. script.println("<script>");
  394. script.println("alert('비밀번호가 틀립니다.')");
  395. script.println("history.back()");
  396. script.println("</script>");
  397. } else if (result == -1) {
  398. PrintWriter script = response.getWriter();
  399. script.println("<script>");
  400. script.println("alert('존재하지 않는 아이디입니다.')");
  401. script.println("history.back()");
  402. script.println("</script>");
  403. } else if (result == -2 ) {
  404. PrintWriter script = response.getWriter();
  405. script.println("<script>");
  406. script.println("alert('데이터베이스 오류가 발생했습니다.')");
  407. script.println("history.back()");
  408. script.println("</script>");
  409. }
  410. %>
  411.  
  412.  
  413. </body>
  414. </html>
  415.  
  416. ★ logoutAction.jsp
  417. <%@ page language="java" contentType="text/html; charset=UTF-8"
  418. pageEncoding="UTF-8"%>
  419. <html>
  420. <head>
  421. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  422. <title>JSP 게시판 웹사이트</title>
  423. </head>
  424. <body>
  425. <%
  426. session.invalidate();
  427. %>
  428. <script>
  429. location.href = 'main.jsp';
  430. </script>
  431. </body>
  432. </html>
  433.  
  434. ★ main.jsp
  435.  
  436. <%@ page language="java" contentType="text/html; charset=UTF-8"
  437. pageEncoding="UTF-8"%>
  438. <%@ page import = "java.io.PrintWriter" %>
  439. <html>
  440. <head>
  441. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  442. <title>JSP 게시판 웹사이트</title>
  443. <link rel="stylesheet" href="css/bootstrap.css">
  444. <link rel="stylesheet" href="css/custom.css">
  445. </head>
  446. <body>
  447. <%
  448. String userId = null;
  449. if(session.getAttribute("userId") != null ) {
  450. userId = (String) session.getAttribute("userId");
  451. }
  452. %>
  453. <nav class= "navbar navbar-default">
  454. <div class="navbar-header">
  455. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
  456. data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  457. <span class="icon-bar"></span>
  458. <span class="icon-bar"></span>
  459. <span class="icon-bar"></span>
  460. </button>
  461. <a class="navbar-brand" href="login.jsp">JSP게시판 웹 사이트</a>
  462. </div>
  463. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  464. <ul class="nav navbar-nav">
  465. <li class="active"><a href="main.jsp">메인</a></li>
  466. <li><a href="bbs.jsp">게시판</a></li>
  467. </ul>
  468. <%
  469. if(userId == null) {
  470. %>
  471. <ul class="nav navbar-nav navbar-right">
  472. <li class="dropdown">
  473. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  474. aria-haspopup="true" aria-expanded="false" >
  475. 접속하기<span class=caret></span>
  476. </a>
  477. <ul class="dropdown-menu">
  478. <li><a href="login.jsp">로그인</a></li>
  479. <li><a href="join.jsp">회원가입</a></li>
  480. </ul>
  481. </li>
  482. </ul>
  483. <%
  484. } else {
  485. %>
  486. <ul class="nav navbar-nav navbar-right">
  487. <li class="dropdown">
  488. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  489. aria-haspopup="true" aria-expanded="false" >
  490. 회원관리<span class=caret></span>
  491. </a>
  492. <ul class="dropdown-menu">
  493.  
  494. <li><a href="logoutAction.jsp">로그아웃</a></li>
  495. </ul>
  496. </li>
  497. </ul>
  498. <%
  499. }
  500. %>
  501. </div>
  502. </nav>
  503. <div class="container">
  504. <div class="jumbotron">
  505. <div class="container">
  506. <h1>해운대팬션</h1>
  507. <p>하늘소리바다소리</p>
  508. <a class="btn btn-primary btn-pull" href="#" role="button">자세히 알아보기</a>
  509. </div>
  510. </div>
  511. </div>
  512. <div class="container">
  513. <div id="myCorousel" class="carousel" data-ride="carousel">
  514. <ol class="carousel-indicators">
  515. <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
  516. <li data-target="#myCarousel" data-slide-to="1"></li>
  517. <li data-target="#myCarousel" data-slide-to="2"></li>
  518. </ol>
  519. <div class="carousel-inner">
  520. <div class="item active">
  521. <img src="images/b1.jpg">
  522. </div>
  523. <div class="item">
  524. <img src="images/b2.jpg">
  525. </div>
  526. <div class="item">
  527. <img src="images/b3.jpg">
  528. </div>
  529. </div>
  530. <a class="left carousel-control" href="#myCarousel" data-slide="prev">
  531. <span class="glyphicon-chevron-left"></span>
  532. </a>
  533. <a class="right carousel-control" href="#myCarousel" data-slide="next">
  534. <span class="glyphicon-chevron-right"></span>
  535. </a>
  536. </div>
  537. </div>
  538. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  539. <script src="js/bootstrap.js"></script>
  540.  
  541. </body>
  542. </html>
  543. ★ update.jsp
  544.  
  545. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
  546. <%@ page import = "java.io.PrintWriter" %>
  547. <%@ page import = "bbs.Bbs" %>
  548. <%@ page import = "bbs.BbsDAO" %>
  549. <html>
  550. <head>
  551. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  552. <title>JSP 게시판 웹사이트</title>
  553. <link rel="stylesheet" href="css/bootstrap.css">
  554. </head>
  555. <body>
  556. <%
  557. String userId = null;
  558. if(session.getAttribute("userId") != null ) {
  559. userId = (String) session.getAttribute("userId");
  560. }
  561. if (userId== null) {
  562. PrintWriter script = response.getWriter();
  563. script.println("<script>");
  564. script.println("alert('로그인을 하세요.')");
  565. script.println("location.href= 'login.jsp' ");
  566. script.println("</script>");
  567. }
  568. int bbsId = 0;
  569. System.out.println(request.getParameter("bbsId"));
  570. if(request.getParameter("bbsId") != null ) {
  571. bbsId= Integer.parseInt(request.getParameter("bbsId"));
  572. }
  573. if(bbsId==0) {
  574. PrintWriter script = response.getWriter();
  575. script.println("<script>");
  576. script.println("alert('유효하지 않은 글입니다.')");
  577. script.println("location.href= 'bbs.jsp' ");
  578. script.println("</script>");
  579. }
  580. Bbs bbs = new BbsDAO().getBbs(bbsId);
  581. if(!userId.equals(bbs.getUserId())){
  582. PrintWriter script = response.getWriter();
  583. script.println("<script>");
  584. script.println("alert('권한이 없습니다.')");
  585. script.println("location.href= 'bbs.jsp' ");
  586. script.println("</script>");
  587. }
  588. %>
  589. <nav class= "navbar navbar-default">
  590. <div class="navbar-header">
  591. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  592. <span class="icon-bar"></span>
  593. <span class="icon-bar"></span>
  594. <span class="icon-bar"></span>
  595. </button>
  596. <a class="navbar-brand" href="login.jsp">JSP게시판 웹 사이트</a>
  597. </div>
  598. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  599. <ul class="nav navbar-nav">
  600. <li><a href="main.jsp">메인</a></li>
  601. <li class="active"><a href="bbs.jsp">게시판</a></li>
  602. </ul>
  603. <ul class="nav navbar-nav navbar-right">
  604. <li class="dropdown">
  605. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  606. aria-haspopup="true" aria-expanded="false" >
  607. 회원관리<span class=caret></span>
  608. </a>
  609. <ul class="dropdown-menu">
  610.  
  611. <li><a href="logoutAction.jsp">로그아웃</a></li>
  612. </ul>
  613. </li>
  614. </ul>
  615. </div>
  616. </nav>
  617. <div class="container">
  618. <div class="row">
  619. <form method="post" action="updateAction.jsp?bbsId=<%=bbsId%>">
  620. <table class="table table-striped" style="text-align:center; border:1px solid #dddddd">
  621. <thead>
  622. <tr>
  623. <th colspan="2" style="background-color: #eeeeee; text-align:center;">게시판 글 수정</th>
  624. </tr>
  625. </thead>
  626. <tbody>
  627. <tr>
  628. <td><input type="text" class="form-control" placeholder="글 제목" name="bbsTitle" maxlength="50" value="<%= bbs.getBbsTitle()%>"></td>
  629. </tr>
  630. <tr>
  631. <td><textarea class="form-control" placeholder="글 내용" name="bbsContent"
  632. maxlength="2048" style="height:350px;"><%= bbs.getBbsContent()%></textarea></td>
  633. </tr>
  634. </tbody>
  635.  
  636. </table>
  637. <input type="submit" class="btn btn-primary pull-right" value="글수정">
  638. </form>
  639. </div>
  640. </div>
  641. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  642. <script src="js/bootstrap.js"></script>
  643. </body>
  644. </html>
  645.  
  646. ★ updateAction.jsp
  647.  
  648. <%@ page language="java" contentType="text/html; charset=UTF-8"
  649. pageEncoding="UTF-8"%>
  650. <%@ page import= "bbs.BbsDAO" %>
  651. <%@ page import= "bbs.Bbs" %>
  652. <%@ page import= "java.io.PrintWriter, java.lang.*" %>
  653. <% request.setCharacterEncoding("UTF-8"); %>
  654. <html>
  655. <head>
  656. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  657. <title>jsp 게시판 웹사이트</title>
  658. </head>
  659. <body>
  660. <%
  661. String userId = null;
  662.  
  663. if(session.getAttribute("userId") != null) {
  664. userId = (String) session.getAttribute("userId");
  665. }
  666. if (userId == null ) {
  667. PrintWriter script = response.getWriter();
  668. script.println("<script>");
  669. script.println("alert('로그인을 하세요')");
  670. script.println("location.href= 'login.jsp' ");
  671. script.println("</script>");
  672. }
  673.  
  674. int bbsId = 0;
  675. if(request.getParameter("bbsId") != null ) {
  676. bbsId= Integer.parseInt(request.getParameter("bbsId"));
  677. }
  678. if(bbsId==0) {
  679. PrintWriter script = response.getWriter();
  680. script.println("<script>");
  681. script.println("alert('유효하지 않은 글입니다.')");
  682. script.println("location.href= 'bbs.jsp' ");
  683. script.println("</script>");
  684. }
  685.  
  686. Bbs bbs = new BbsDAO().getBbs(bbsId);
  687. if(!userId.equals(bbs.getUserId())){
  688. PrintWriter script = response.getWriter();
  689. script.println("<script>");
  690. script.println("alert('권한이 없습니다.')");
  691. script.println("location.href= 'bbs.jsp' ");
  692. script.println("</script>");
  693. }
  694.  
  695. else {
  696. if (request.getParameter("bbsTitle")==null || request.getParameter("bbsContent")==null
  697. || request.getParameter("bbsTitle").equals("")|| request.getParameter("bbsContent").equals("")) {
  698. PrintWriter script = response.getWriter();
  699. script.println("<script>");
  700. script.println("alert('입력이 안 된 사항이 있습니다.')");
  701. script.println("history.back()");
  702. script.println("</script>");
  703. } else {
  704.  
  705. BbsDAO bbsDAO = new BbsDAO();
  706. int result = bbsDAO.update(bbsId, request.getParameter("bbsTitle"), request.getParameter("bbsContent"));
  707.  
  708. if(result== - 1) {
  709. PrintWriter script = response.getWriter();
  710. script.println("<script>");
  711. script.println("alert('글수정이 실패했습니다..')");
  712. script.println("history.back()");
  713. script.println("</script>");
  714. } else {
  715. PrintWriter script = response.getWriter();
  716. script.println("<script>");
  717. script.println("location.href= 'bbs.jsp' ");
  718. script.println("</script>");
  719. }
  720. }
  721. }
  722. %>
  723. </body>
  724. </html>
  725.  
  726. ★ view.jsp
  727.  
  728. <%@ page language="java" contentType="text/html; charset=UTF-8"
  729. pageEncoding="UTF-8"%>
  730. <%@ page import ="java.io.PrintWriter" %>
  731. <%@ page import ="bbs.Bbs" %>
  732. <%@ page import ="bbs.BbsDAO" %>
  733.  
  734. <html>
  735. <head>
  736. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  737. <title>JSP 게시판 웹사이트</title>
  738. <link rel="stylesheet" href="css/bootstrap.css">
  739. </head>
  740. <body>
  741. <%
  742. String userId = null;
  743. if(session.getAttribute("userId") != null ) {
  744. userId = (String) session.getAttribute("userId");
  745. }
  746. int bbsId = -1;
  747. if(request.getParameter("bbsId") != null ) {
  748. bbsId= Integer.parseInt(request.getParameter("bbsId"));
  749. }
  750. if(bbsId == -1) {
  751. PrintWriter script = response.getWriter();
  752. script.println("<script>");
  753. script.println("alert('유효하지 않은 글입니다.')");
  754. script.println("location.href= 'bbs.jsp' ");
  755. script.println("</script>");
  756. }
  757. Bbs bbs = new BbsDAO().getBbs(bbsId);
  758. %>
  759. <nav class= "navbar navbar-default">
  760. <div class="navbar-header">
  761. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
  762. data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  763. <span class="icon-bar"></span>
  764. <span class="icon-bar"></span>
  765. <span class="icon-bar"></span>
  766. </button>
  767. <a class="navbar-brand" href="login.jsp">JSP게시판 웹 사이트</a>
  768. </div>
  769. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  770. <ul class="nav navbar-nav">
  771. <li><a href="main.jsp">메인</a></li>
  772. <li class="active"><a href="bbs.jsp">게시판</a></li>
  773. </ul>
  774. <%
  775. if(userId == null) {
  776. %>
  777. <ul class="nav navbar-nav navbar-right">
  778. <li class="dropdown">
  779. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  780. aria-haspopup="true" aria-expanded="false" >
  781. 접속하기<span class=caret></span>
  782. </a>
  783. <ul class="dropdown-menu">
  784. <li><a href="login.jsp">로그인</a></li>
  785. <li><a href="join.jsp">회원가입</a></li>
  786. </ul>
  787. </li>
  788. </ul>
  789. <%
  790. } else {
  791. %>
  792. <ul class="nav navbar-nav navbar-right">
  793. <li class="dropdown">
  794. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  795. aria-haspopup="true" aria-expanded="false" >
  796. 회원관리<span class=caret></span>
  797. </a>
  798. <ul class="dropdown-menu">
  799.  
  800. <li><a href="logoutAction.jsp">로그아웃</a></li>
  801. </ul>
  802. </li>
  803. </ul>
  804. <%
  805. }
  806. %>
  807. </div>
  808. </nav>
  809. <div class="container">
  810. <div class="row">
  811. <table class="table table-striped" style="text-align:center; border:1px solid #dddddd">
  812. <thead>
  813. <tr>
  814. <th colspan="3" style="background-color: #eeeeee; text-align:center;">게시판 글보기</th>
  815. </tr>
  816. </thead>
  817. <tbody>
  818. <tr>
  819. <td style="width:20%">글 제목</td>
  820. <td colspan="2"><%= bbs.getBbsTitle().replaceAll(" ", "&nbsp;").replaceAll("<","&lt").replaceAll(" ","&gt")
  821. .replaceAll("\n","</br>") %></td>
  822. </tr>
  823. <tr>
  824. <td>작성자</td>
  825. <td colspan="2"><%= bbs.getUserId() %></td>
  826. </tr>
  827. <tr>
  828. <td>작성시간</td>
  829. <td colspan="2"><%= bbs.getBbsDate().substring(0,11)+
  830. bbs.getBbsDate().substring(11,13)+ "시 "+ bbs.getBbsDate().substring(14,16)+ "분" %></td>
  831. </tr>
  832. <tr>
  833. <td>내용</td>
  834. <td colspan="2" style="min-height:200px; text-align:left;"><%=bbs.getBbsContent().replaceAll(" ", "&nbsp;")
  835. .replaceAll("<","&lt").replaceAll(" ","&gt").replaceAll("\n","</br>") %></td>
  836. </tr>
  837. </tbody>
  838. </table>
  839. <a href="bbs.jsp" class="btn btn-primary">목록</a>
  840. <%
  841. if(userId != null && userId.equals(bbs.getUserId())) {
  842. %>
  843. <a href="update.jsp?bbsId=<%=bbsId %>" class="btn btn-primary">수정</a>
  844. <a onclick="return confirm('정말로 삭제하시겠습니까?')" href="deleteAction.jsp?bbsId=<%=bbsId %>" class="btn btn-primary">삭제</a>
  845. <%
  846. }
  847. %>
  848. </div>
  849. </div>
  850. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  851. <script src="js/bootstrap.js"></script>
  852. </body>
  853. </html>
  854.  
  855. ★ write.jsp
  856.  
  857. <%@ page language="java" contentType="text/html; charset=UTF-8"
  858. pageEncoding="UTF-8"%>
  859. <%@ page import = "java.io.PrintWriter" %>
  860. <html>
  861. <head>
  862. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  863. <title>JSP 게시판 웹사이트</title>
  864. <link rel="stylesheet" href="css/bootstrap.css">
  865. </head>
  866. <body>
  867. <%
  868. String userId = null;
  869. if(session.getAttribute("userId") != null ) {
  870. userId = (String) session.getAttribute("userId");
  871. }
  872. %>
  873.  
  874.  
  875. <nav class= "navbar navbar-default">
  876. <div class="navbar-header">
  877. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
  878. data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
  879. <span class="icon-bar"></span>
  880. <span class="icon-bar"></span>
  881. <span class="icon-bar"></span>
  882. </button>
  883. <a class="navbar-brand" href="login.jsp">JSP게시판 웹 사이트</a>
  884. </div>
  885. <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  886. <ul class="nav navbar-nav">
  887. <li><a href="main.jsp">메인</a></li>
  888. <li class="active"><a href="bbs.jsp">게시판</a></li>
  889. </ul>
  890. <%
  891. if(userId == null) {
  892. %>
  893. <ul class="nav navbar-nav navbar-right">
  894. <li class="dropdown">
  895. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  896. aria-haspopup="true" aria-expanded="false" >
  897. 접속하기<span class=caret></span>
  898. </a>
  899. <ul class="dropdown-menu">
  900. <li><a href="login.jsp">로그인</a></li>
  901. <li><a href="join.jsp">회원가입</a></li>
  902. </ul>
  903. </li>
  904. </ul>
  905. <%
  906. } else {
  907. %>
  908. <ul class="nav navbar-nav navbar-right">
  909. <li class="dropdown">
  910. <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
  911. aria-haspopup="true" aria-expanded="false" >
  912. 회원관리<span class=caret></span>
  913. </a>
  914. <ul class="dropdown-menu">
  915.  
  916. <li><a href="logoutAction.jsp">로그아웃</a></li>
  917. </ul>
  918. </li>
  919. </ul>
  920. <%
  921. }
  922. %>
  923. </div>
  924. </nav>
  925. <div class="container">
  926. <div class="row">
  927. <form method="post" action="writeAction.jsp">
  928. <table class="table table-striped" style="text-align:center; border:1px solid #dddddd">
  929. <thead>
  930. <tr>
  931. <th colspan="2" style="background-color: #eeeeee; text-align:center;">게시판 글쓰기 양식</th>
  932. </tr>
  933. </thead>
  934. <tbody>
  935. <tr>
  936. <td><input type="text" class="form-control" placeholder="글 제목" name="bbsTitle" maxlength="50"></td>
  937. </tr>
  938. <tr>
  939. <td><textarea class="form-control" placeholder="글 내용" name="bbsContent" maxlength="2048" style="height:350px;">
  940. </textarea></td>
  941. </tr>
  942. </tbody>
  943.  
  944. </table>
  945. <input type="submit" class="btn btn-primary pull-right" value="글쓰기">
  946. </form>
  947. </div>
  948. </div>
  949. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  950. <script src="js/bootstrap.js"></script>
  951.  
  952. </body>
  953. </html>
  954.  
  955. ★ Bbs.java
  956.  
  957. package bbs;
  958. public class Bbs {
  959. private int bbsId;
  960. private String bbsTitle;
  961. private String userId;
  962. private String bbsDate;
  963. private String bbsContent;
  964. private int bbsAvailable;
  965.  
  966. public int getBbsId() {
  967. return bbsId;
  968. }
  969. public void setBbsId(int bbsId) {
  970. this.bbsId = bbsId;
  971. }
  972. public String getBbsTitle() {
  973. return bbsTitle;
  974. }
  975. public void setBbsTitle(String bbsTitle) {
  976. this.bbsTitle = bbsTitle;
  977. }
  978. public String getUserId() {
  979. return userId;
  980. }
  981. public void setUserId(String userId) {
  982. this.userId = userId;
  983. }
  984. public String getBbsDate() {
  985. return bbsDate;
  986. }
  987. public void setBbsDate(String bbsDate) {
  988. this.bbsDate = bbsDate;
  989. }
  990. public String getBbsContent() {
  991. return bbsContent;
  992. }
  993. public void setBbsContent(String bbsContent) {
  994. this.bbsContent = bbsContent;
  995. }
  996. public int getBbsAvailable() {
  997. return bbsAvailable;
  998. }
  999. public void setBbsAvailable(int bbsAvailable) {
  1000. this.bbsAvailable = bbsAvailable;
  1001. }
  1002. }
  1003.  
  1004.  
  1005. ★ BbsDAO.java
  1006.  
  1007. package bbs;
  1008.  
  1009. import java.sql.Connection;
  1010. import java.sql.DriverManager;
  1011. import java.sql.PreparedStatement;
  1012. import java.sql.ResultSet;
  1013. import java.util.ArrayList;
  1014.  
  1015. public class BbsDAO {
  1016. private Connection con;
  1017. private PreparedStatement pstmt;
  1018. private ResultSet rs;
  1019.  
  1020. public BbsDAO (){
  1021. try {
  1022. String dburl="jdbc:mysql://localhost:3306/shift";
  1023. String dbId ="shift";
  1024. String dbPassword = "shift";
  1025. Class.forName("com.mysql.jdbc.Driver");
  1026. con= DriverManager.getConnection(dburl, dbId, dbPassword);
  1027. } catch (Exception e) {
  1028. e.printStackTrace();
  1029. }
  1030. }
  1031.  
  1032. public String getDate (){
  1033. String SQL = "SELECT NOW()";
  1034. try {
  1035. PreparedStatement pstmt = con.prepareStatement(SQL);
  1036. rs = pstmt.executeQuery();
  1037. if(rs.next()) {
  1038. return rs.getString(1);
  1039. }
  1040. } catch (Exception e) {
  1041. e.printStackTrace();
  1042. }
  1043. return ""; // 데이터메이스 오류
  1044. }
  1045.  
  1046.  
  1047. public int getNext (){
  1048. String SQL = "SELECT bbsId FROM BBS ORDER BY bbsId DESC";
  1049. try {
  1050. PreparedStatement pstmt = con.prepareStatement(SQL);
  1051. rs = pstmt.executeQuery();
  1052. if(rs.next()) {
  1053. return rs.getInt(1)+1;
  1054. }
  1055. } catch (Exception e) {
  1056. e.printStackTrace();
  1057. }
  1058. return -1; // 데이터메이스 오류
  1059. }
  1060.  
  1061.  
  1062. public int write (String bbsTitle, String userId, String bbsContent){
  1063. String SQL = "INSERT INTO BBS VALUES (?, ?, ? , ? ,? ,? )";
  1064. try {
  1065. PreparedStatement pstmt = con.prepareStatement(SQL);
  1066. pstmt.setInt(1, getNext());
  1067. pstmt.setString(2, bbsTitle);
  1068. pstmt.setString(3, userId);
  1069. pstmt.setString(4, getDate());
  1070. pstmt.setString(5, bbsContent);
  1071. pstmt.setInt(6, 1);
  1072. return pstmt.executeUpdate();
  1073.  
  1074. } catch (Exception e) {
  1075. e.printStackTrace();
  1076. }
  1077. return -1; // 데이터메이스 오류
  1078. }
  1079.  
  1080.  
  1081. public ArrayList <Bbs> getList (int pageNumber) {
  1082. String SQL = "SELECT * FROM BBS WHERE bbsId < ? AND bbsAvailable = 1 ORDER BY bbsId DESC LIMIT 10";
  1083. ArrayList <Bbs> list = new ArrayList<Bbs> ();
  1084. try {
  1085. PreparedStatement pstmt = con.prepareStatement(SQL);
  1086. pstmt.setInt(1, getNext() - (pageNumber -1) * 10);
  1087. rs = pstmt.executeQuery();
  1088. while (rs.next()) {
  1089. Bbs bbs = new Bbs();
  1090. bbs.setBbsId(rs.getInt(1));
  1091. bbs.setBbsTitle(rs.getString(2));
  1092. bbs.setUserId(rs.getString(3));
  1093. bbs.setBbsDate(rs.getString(4));
  1094. bbs.setBbsContent(rs.getString(5));
  1095. bbs.setBbsAvailable(rs.getInt(6));
  1096. list.add(bbs);
  1097. }
  1098. } catch (Exception e) {
  1099. e.printStackTrace();
  1100. }
  1101. return list;
  1102.  
  1103. }
  1104.  
  1105. public boolean nextPage (int pageNumber) {
  1106. String SQL = "SELECT * FROM BBS WHERE bbsId < ? AND bbsAvailable =1";
  1107. try {
  1108. PreparedStatement pstmt = con.prepareStatement(SQL);
  1109. pstmt.setInt(1, getNext()- (pageNumber-1)*10);
  1110. rs = pstmt.executeQuery();
  1111. if (rs.next()) {
  1112. return true;
  1113. }
  1114. } catch (Exception e) {
  1115. e.printStackTrace();
  1116. }
  1117. return false;
  1118. }
  1119.  
  1120.  
  1121. public Bbs getBbs (int bbsId) {
  1122. String SQL = "SELECT * FROM bbs WHERE bbsId= ?";
  1123. try {
  1124. PreparedStatement pstmt = con.prepareStatement(SQL);
  1125. pstmt.setInt(1, bbsId);
  1126. rs = pstmt.executeQuery();
  1127. if (rs.next()) {
  1128. Bbs bbs = new Bbs();
  1129. bbs.setBbsId(rs.getInt(1));
  1130. bbs.setBbsTitle(rs.getString(2));
  1131. bbs.setUserId(rs.getString(3));
  1132. bbs.setBbsDate(rs.getString(4));
  1133. bbs.setBbsContent(rs.getString(5));
  1134. bbs.setBbsAvailable(rs.getInt(6));
  1135. return bbs;
  1136. }
  1137. } catch (Exception e) {
  1138. e.printStackTrace();
  1139. }
  1140. return null;
  1141. }
  1142.  
  1143. public int update (int bbsId, String bbsTitle, String bbsContent) {
  1144. String SQL = "update bbs set bbsTitle = ? , bbsContent = ? where bbsId= ? ";
  1145. try {
  1146. PreparedStatement pstmt = con.prepareStatement(SQL);
  1147. pstmt.setString(1, bbsTitle);
  1148. pstmt.setString(2, bbsContent);
  1149. pstmt.setInt(3, bbsId);
  1150. return pstmt.executeUpdate();
  1151.  
  1152. } catch (Exception e) {
  1153. e.printStackTrace();
  1154. }
  1155. return -1;
  1156. }
  1157.  
  1158. public int delete (int bbsId) {
  1159. String SQL = "update bbs set bbsAvailable = 0 where bbsId= ? ";
  1160. try {
  1161. PreparedStatement pstmt = con.prepareStatement(SQL);
  1162. pstmt.setInt(1, bbsId);
  1163. return pstmt.executeUpdate();
  1164.  
  1165. } catch (Exception e) {
  1166. e.printStackTrace();
  1167. }
  1168. return -1;
  1169. }
  1170.  
  1171. }
  1172.  
  1173.  
  1174. ★User.java
  1175.  
  1176. package user;
  1177.  
  1178. public class User {
  1179. private String userId;
  1180. private String userPassword;
  1181. private String userName;
  1182. private String userGender;
  1183. private String userEmail;
  1184. public String getUserId() {
  1185. return userId;
  1186. }
  1187. public void setUserId(String userId) {
  1188. this.userId = userId;
  1189. }
  1190. public String getUserPassword() {
  1191. return userPassword;
  1192. }
  1193. public void setUserPassword(String userPassword) {
  1194. this.userPassword = userPassword;
  1195. }
  1196. public String getUserName() {
  1197. return userName;
  1198. }
  1199. public void setUserName(String userName) {
  1200. this.userName = userName;
  1201. }
  1202. public String getUserGender() {
  1203. return userGender;
  1204. }
  1205. public void setUserGender(String userGender) {
  1206. this.userGender = userGender;
  1207. }
  1208. public String getUserEmail() {
  1209. return userEmail;
  1210. }
  1211. public void setUserEmail(String userEmail) {
  1212. this.userEmail = userEmail;
  1213. }
  1214.  
  1215.  
  1216. }
  1217.  
  1218. ★ UserDAO.java
  1219.  
  1220. package user;
  1221.  
  1222. import java.sql.Connection;
  1223. import java.sql.DriverManager;
  1224. import java.sql.PreparedStatement;
  1225. import java.sql.ResultSet;
  1226.  
  1227. public class UserDAO {
  1228. private Connection con;
  1229. private PreparedStatement pstmt;
  1230. private ResultSet rs;
  1231.  
  1232. public UserDAO (){
  1233. try {
  1234. String dburl="jdbc:mysql://localhost:3306/shift";
  1235. String dbId ="shift";
  1236. String dbPassword = "shift";
  1237. Class.forName("com.mysql.jdbc.Driver");
  1238. con = DriverManager.getConnection(dburl, dbId, dbPassword);
  1239. } catch (Exception e) {
  1240. e.printStackTrace();
  1241. }
  1242. }
  1243.  
  1244. public int login (String userId, String userPassword) {
  1245. String SQL = "SELECT userPassword FROM USER WHERE userId=? " ;
  1246. try {
  1247. pstmt = con.prepareStatement(SQL);
  1248. pstmt.setString(1, userId);
  1249. rs = pstmt.executeQuery();
  1250. if (rs.next() ) {
  1251. if(rs.getString(1).equals(userPassword))
  1252. return 1;
  1253. else return 0;
  1254.  
  1255.  
  1256. }
  1257. return -1;
  1258. } catch (Exception e) {
  1259. e.printStackTrace();
  1260. }
  1261. return -2;
  1262. }
  1263.  
  1264. public int join(User user){
  1265. String SQL = "INSERT INTO USER VALUES (?, ?, ?, ?, ?)";
  1266. try {
  1267. pstmt = con.prepareStatement(SQL);
  1268. pstmt.setString(1, user.getUserId());
  1269. pstmt.setString(2, user.getUserPassword());
  1270. pstmt.setString(3, user.getUserName());
  1271. pstmt.setString(4, user.getUserGender());
  1272. pstmt.setString(5, user.getUserEmail());
  1273. return pstmt.executeUpdate();
  1274. } catch (Exception e) {
  1275. e.printStackTrace();
  1276. }
  1277. return -1;
  1278. }
  1279.  
  1280.  
  1281. }
  1282.  
  1283.  
  1284.  
  1285.  
  1286. ★ writeAction.jsp
  1287.  
  1288. <%@ page language="java" contentType="text/html; charset=UTF-8"
  1289. pageEncoding="UTF-8"%>
  1290. <%@ page import= "bbs.BbsDAO" %>
  1291. <%@ page import= "java.io.PrintWriter" %>
  1292. <% request.setCharacterEncoding("UTF-8"); %>
  1293. <jsp:useBean id="bbs" class="bbs.Bbs" scope="page" />
  1294. <jsp:setProperty name="bbs" property="bbsTitle" />
  1295. <jsp:setProperty name="bbs" property="bbsContent" />
  1296. <html>
  1297. <head>
  1298. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  1299. <title>jsp 게시판 웹사이트</title>
  1300. </head>
  1301. <body>
  1302. <%
  1303. String userId = null;
  1304.  
  1305. if(session.getAttribute("userId") != null) {
  1306. userId = (String) session.getAttribute("userId");
  1307. }
  1308.  
  1309. if (userId == null ) {
  1310. PrintWriter script = response.getWriter();
  1311. script.println("<script>");
  1312. script.println("alert('로그인을 하세요')");
  1313. script.println("location.href= 'login.jsp' ");
  1314. script.println("</script>");
  1315. } else {
  1316. if (bbs.getBbsTitle()==null || bbs.getBbsContent()==null) {
  1317. PrintWriter script = response.getWriter();
  1318. script.println("<script>");
  1319. script.println("alert('입력이 안 된 사항이 있습니다.')");
  1320. script.println("history.back()");
  1321. script.println("</script>");
  1322. } else {
  1323.  
  1324. BbsDAO bbsDAO = new BbsDAO();
  1325. int result = bbsDAO.write(bbs.getBbsTitle(), userId, bbs.getBbsContent());
  1326. if(result== - 1) {
  1327. PrintWriter script = response.getWriter();
  1328. script.println("<script>");
  1329. script.println("alert('글쓰기에 실패했습니다..')");
  1330. script.println("history.back()");
  1331. script.println("</script>");
  1332. } else {
  1333. PrintWriter script = response.getWriter();
  1334. script.println("<script>");
  1335. script.println("location.href= 'bbs.jsp' ");
  1336. script.println("</script>");
  1337. }
  1338. }
  1339. }
  1340. %>
  1341. </body>
  1342. </html>
  1343.  
  1344. ★ deleteAction.jsp
  1345.  
  1346. <%@ page language="java" contentType="text/html; charset=UTF-8"
  1347. pageEncoding="UTF-8"%>
  1348. <%@ page import= "bbs.BbsDAO" %>
  1349. <%@ page import= "bbs.Bbs" %>
  1350. <%@ page import= "java.io.PrintWriter" %>
  1351. <% request.setCharacterEncoding("UTF-8"); %>
  1352. <html>
  1353. <head>
  1354. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  1355. <title>jsp 게시판 웹사이트</title>
  1356. </head>
  1357. <body>
  1358. <%
  1359. String userId = null;
  1360.  
  1361. if(session.getAttribute("userId") != null) {
  1362. userId = (String) session.getAttribute("userId");
  1363. }
  1364. if (userId == null ) {
  1365. PrintWriter script = response.getWriter();
  1366. script.println("<script>");
  1367. script.println("alert('로그인을 하세요')");
  1368. script.println("location.href= 'login.jsp' ");
  1369. script.println("</script>");
  1370. }
  1371.  
  1372. int bbsId = 0;
  1373. if(request.getParameter("bbsId") != null ) {
  1374. bbsId= Integer.parseInt(request.getParameter("bbsId"));
  1375. }
  1376. if(bbsId==0) {
  1377. PrintWriter script = response.getWriter();
  1378. script.println("<script>");
  1379. script.println("alert('유효하지 않은 글입니다.')");
  1380. script.println("location.href= 'bbs.jsp' ");
  1381. script.println("</script>");
  1382. }
  1383.  
  1384. Bbs bbs = new BbsDAO().getBbs(bbsId);
  1385. if(!userId.equals(bbs.getUserId())){
  1386. PrintWriter script = response.getWriter();
  1387. script.println("<script>");
  1388. script.println("alert('권한이 없습니다.')");
  1389. script.println("location.href= 'bbs.jsp' ");
  1390. script.println("</script>");
  1391. }
  1392.  
  1393. else {
  1394. BbsDAO bbsDAO = new BbsDAO();
  1395.  
  1396. int result = bbsDAO.delete(bbsId);
  1397.  
  1398. if(result== - 1) {
  1399. PrintWriter script = response.getWriter();
  1400. script.println("<script>");
  1401. script.println("alert('글삭제에 실패했습니다..')");
  1402. script.println("location.href= 'bbs.jsp' ");
  1403. script.println("</script>");
  1404. } else {
  1405. PrintWriter script = response.getWriter();
  1406. script.println("<script>");
  1407. script.println("location.href= 'bbs.jsp' ");
  1408. script.println("</script>");
  1409. }
  1410. }
  1411. %>
  1412. </body>
  1413. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement