Advertisement
hyunjeong

Untitled

Aug 29th, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 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, java.lang.*" %>
  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. if (request.getParameter("bbsTitle")==null || request.getParameter("bbsContent")==null
  50. || request.getParameter("bbsTitle").equals("")|| request.getParameter("bbsContent").equals("")) {
  51. PrintWriter script = response.getWriter();
  52. script.println("<script>");
  53. script.println("alert('입력이 안 된 사항이 있습니다.')");
  54. script.println("history.back()");
  55. script.println("</script>");
  56. } else {
  57.  
  58. BbsDAO bbsDAO = new BbsDAO();
  59. int result = bbsDAO.update(bbsId, request.getParameter("bbsTitle"), request.getParameter("bbsContent"));
  60.  
  61. if(result== - 1) {
  62. PrintWriter script = response.getWriter();
  63. script.println("<script>");
  64. script.println("alert('글수정이 실패했습니다..')");
  65. script.println("history.back()");
  66. script.println("</script>");
  67. } else {
  68. PrintWriter script = response.getWriter();
  69. script.println("<script>");
  70. script.println("location.href= 'bbs.jsp' ");
  71. script.println("</script>");
  72. }
  73. }
  74. }
  75. %>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement