hyunjeong

Untitled

Aug 29th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ page import= "bbs.BbsDAO" %>
  4. <%@ page import= "bbs.Bbs" %>
  5. <%@ page import= "java.io.PrintWriter" %>
  6. <% request.setCharacterEncoding("UTF-8"); %>
  7. <html>
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  10. <title>jsp 게시판 웹사이트</title>
  11. </head>
  12. <body>
  13. <%
  14. String userId = null;
  15.  
  16. if(session.getAttribute("userId") != null) {
  17. userId = (String) session.getAttribute("userId");
  18. }
  19. if (userId == null ) {
  20. PrintWriter script = response.getWriter();
  21. script.println("<script>");
  22. script.println("alert('로그인을 하세요')");
  23. script.println("location.href= 'login.jsp' ");
  24. script.println("</script>");
  25. }
  26.  
  27. int bbsId = 0;
  28. if(request.getParameter("bbsId") != null ) {
  29. bbsId= Integer.parseInt(request.getParameter("bbsId"));
  30. }
  31. if(bbsId==0) {
  32. PrintWriter script = response.getWriter();
  33. script.println("<script>");
  34. script.println("alert('유효하지 않은 글입니다.')");
  35. script.println("location.href= 'bbs.jsp' ");
  36. script.println("</script>");
  37. }
  38.  
  39. Bbs bbs = new BbsDAO().getBbs(bbsId);
  40. if(!userId.equals(bbs.getUserId())){
  41. PrintWriter script = response.getWriter();
  42. script.println("<script>");
  43. script.println("alert('권한이 없습니다.')");
  44. script.println("location.href= 'bbs.jsp' ");
  45. script.println("</script>");
  46. }
  47.  
  48. else {
  49. BbsDAO bbsDAO = new BbsDAO();
  50.  
  51. int result = bbsDAO.delete(bbsId);
  52.  
  53. if(result== - 1) {
  54. PrintWriter script = response.getWriter();
  55. script.println("<script>");
  56. script.println("alert('글삭제에 실패했습니다..')");
  57. script.println("location.href= 'bbs.jsp' ");
  58. script.println("</script>");
  59. } else {
  60. PrintWriter script = response.getWriter();
  61. script.println("<script>");
  62. script.println("location.href= 'bbs.jsp' ");
  63. script.println("</script>");
  64. }
  65. }
  66. %>
  67. </body>
  68. </html>
Add Comment
Please, Sign In to add comment