hyunjeong

Untitled

Aug 29th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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= "java.io.PrintWriter" %>
  5. <% request.setCharacterEncoding("UTF-8"); %>
  6. <jsp:useBean id="bbs" class="bbs.Bbs" scope="page" />
  7. <jsp:setProperty name="bbs" property="bbsTitle" />
  8. <jsp:setProperty name="bbs" property="bbsContent" />
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12. <title>jsp 게시판 웹사이트</title>
  13. </head>
  14. <body>
  15. <%
  16. String userId = null;
  17.  
  18. if(session.getAttribute("userId") != null) {
  19. userId = (String) session.getAttribute("userId");
  20. }
  21.  
  22. if (userId == null ) {
  23. PrintWriter script = response.getWriter();
  24. script.println("<script>");
  25. script.println("alert('로그인을 하세요')");
  26. script.println("location.href= 'login.jsp' ");
  27. script.println("</script>");
  28. } else {
  29. if (bbs.getBbsTitle()==null || bbs.getBbsContent()==null) {
  30. PrintWriter script = response.getWriter();
  31. script.println("<script>");
  32. script.println("alert('입력이 안 된 사항이 있습니다.')");
  33. script.println("history.back()");
  34. script.println("</script>");
  35. } else {
  36.  
  37. BbsDAO bbsDAO = new BbsDAO();
  38. int result = bbsDAO.write(bbs.getBbsTitle(), userId, bbs.getBbsContent());
  39. if(result== - 1) {
  40. PrintWriter script = response.getWriter();
  41. script.println("<script>");
  42. script.println("alert('글쓰기에 실패했습니다..')");
  43. script.println("history.back()");
  44. script.println("</script>");
  45. } else {
  46. PrintWriter script = response.getWriter();
  47. script.println("<script>");
  48. script.println("location.href= 'bbs.jsp' ");
  49. script.println("</script>");
  50. }
  51. }
  52. }
  53. %>
  54. </body>
  55. </html>
Add Comment
Please, Sign In to add comment