<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "com.shdev.bbs.BbsDAO" %>
<%@ page import = "java.io.PrintWriter" %> <!-- javascript를 사용할 수 있게 함 -->
<% request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id = "bbs" class = "com.shdev.bbs.Bbs" scope = "page"/>
<jsp:setProperty name = "bbs" property = "bbsTitle"/>
<jsp:setProperty name = "bbs" property = "bbsContent"/>
<!DOCTYPE html>
<html lang="en">
<head>
<title>BBS</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<%
String userID = null;
PrintWriter script = response.getWriter();
BbsDAO bbsDAO = new BbsDAO();
if(session.getAttribute("userID") != null){
userID = (String)session.getAttribute("userID");
}
if(userID == null){
script.println("<script>");
script.println("alert('Please, Log in.')");
script.println("location.href = 'login.jsp'");
script.println("</script>");
}else{
if(bbs.getBbsTitle() == null || bbs.getBbsContent() == null){
script.println("<script>");
script.println("alert('입력이 안 된 사항이 있습니다.');");
script.println("</script>");
}else{
bbs.setUserID(userID);
int result = bbsDAO.write(bbs);
if(result == 1){
script.println("<script>");
script.println("location.href = 'BBS.jsp'");
script.println("</script>");
}else if(result == -2){
script.println("<script>");
script.println("alert('DATABASE ERROR')");
script.println("history.back();");
script.println("</script>");
}
}
}
/* if(result == 1){
session.setAttribute("userID", user.getUserID());
script.println("<script>");
script.println("location.href = 'main.jsp'");
script.println("</script>");
}else{
script.println("<script>");
script.println("alert('이미 존재하는 아이디 입니다.')");
script.println("history.back()");
script.println("</script>");
*/
/* if(result == 1){
script.println("<script>");
script.println("location.href = 'BBS.jsp'");
script.println("</script>");
}else if(result == -2){
script.println("<script>");
script.println("alert('DATABASE ERROR');");
script.println("history.back();");
script.println("</script>");
} */
%>
</body>
</html>
'개인 프로젝트 > 게시판' 카테고리의 다른 글
[JSP 게시판] BbsDAO.java (0) | 2018.02.03 |
---|---|
[JSP 게시판] Bbs.java (0) | 2018.02.03 |
[JSP 게시판] write.jsp : 게시글 작성 (0) | 2018.02.03 |
[JSP 게시판] view.jsp : 게시글 보기 (0) | 2018.02.03 |
[JSP 게시판] updateAction.jsp : 게시글 업데이트 (0) | 2018.02.03 |