๋ก๊ทธ์ธ ํ์ด์ง , ๊ฒ์ํ ๋ง๋ค๊ธฐ , ๊ฒ์๊ธ ์
๋ก๋ ๋ฐ ํ์ธ
<!-- login.jsp
๋ฉ์ธ ๋ก๊ทธ์ธ ํ์ผ -->
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>๋ก๊ทธ์ธ ํ์ด์ง</h1>
<form action="login-ok.jsp" method="post">
ID : <input type="text" name="id"><br>
PW : <input type="password" name="pw"><br>
<input type="submit" value="๋ก๊ทธ์ธ">
</form>
</body>
</html>
<!-- board.jsp
๋ฉ์ธ ๊ฒ์ํ ๊ตฌ์กฐ -->
<%@page import="board.BoardVO"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>๊ฒ์ํ</h1>
<table border="1">
<tr>
<td>No</td> <td>๊ธ์ ๋ชฉ</td> <td>์์ฑ์</td> <td>์์ฑ์ผ</td>
</tr>
<%
ArrayList<BoardVO> list =(ArrayList<BoardVO>)session.getAttribute("list");
if(list !=null){
for(BoardVO vo : list ){
%>
<tr>
<td><%=vo.getNo() %></td> <td><a href="board-detail.jsp?no=<%=vo.getNo() %>"><%=vo.getTitle() %></a></td> <td><%=vo.getAuthor() %></td> <td><%=vo.getNowDate() %></td>
</tr>
<%
}
}
%>
</table>
<button onclick="javascript:location.href='board-regist.jsp'">์ ๊ธ ๋ฑ๋ก</button>
</body>
</html>
<!-- board-detail.jsp
๊ฒ์ํ ๊ฒ์๊ธ ํ์ธ -->
<%@page import="board.BoardVO"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>๊ธ ์์ธ</h1>
<%
ArrayList<BoardVO> list = (ArrayList<BoardVO>)session.getAttribute("list");
int no = Integer.parseInt(request.getParameter("no"));
for (BoardVO vo : list){
if(vo.getNo()==no){
%>
์ ๋ชฉ : <%=vo.getTitle() %><br>
์์ฑ์ :<%=vo.getAuthor() %> <br>
์์ฑ์ผ :<%=vo.getNowDate() %> <br>
๋ด์ฉ : <%=vo.getContent() %><br>
<%
}
}
%>
</body>
</html>
<!--board-regist.jsp
๊ฒ์๊ธ ๋ฑ๋ก ํ์ผ -->
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>์ ๊ธ ๋ฑ๋ก</h1>
<form action="board-regist-ok.jsp" method="post">
no : <input type="text" name="no"><br>
์ ๋ชฉ : <input type="text" name="title"><br>
๋ด์ฉ : <textarea name="content"></textarea><br>
<input type="submit" value="๋ฑ๋ก">
</form>
</body>
</html>
<!-- login-ok.jsp
๋ก๊ทธ์ธ ๊ณ์ ๊ด๋ฆฌ ํ์ผ -->
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
String id = request.getParameter("id");
String pw = request.getParameter("pw");
//DB์ id,pw๋ฅผ ๋๊ฒจ์ ์ค์ ์กด์ฌํ๋ ๊ณ์ ์ธ์ง ํ์ธ
if(id.equals("admin") && pw.equals("1234")){
// ์ฑ๊ณต
session.setAttribute("session_id","id");
response.sendRedirect("board.jsp");
} else{
// ์คํจ
response.sendRedirect("login.jsp");
}
%>
</body>
</html>
<!-- board.regist-ok.jsp
๊ฒ์ํ ๋ก์ง -->
<%@page import="board.BoardVO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
int no =Integer.parseInt(request.getParameter("no")); // NO
String title = request.getParameter("title"); // ์ ๋ชฉ
String content = request.getParameter("content"); // ๋ด์ฉ
String author = (String) session.getAttribute("session_id"); // ์์ฑ์
Date nowDate = new Date(); // ์์ฑ์ผ
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(nowDate);
BoardVO vo = new BoardVO();
vo.setNo(no);
vo.setTitle(title);
vo.setContent(content);
vo.setAuthor(author);
vo.setNowDate(date);
ArrayList<BoardVO> list = (ArrayList<BoardVO>)session.getAttribute("list");
if(list == null){
list = new ArrayList<BoardVO>();
}else{
list.add(vo);
session.setAttribute("list", list);
}
response.sendRedirect("board.jsp");
%>
</body>
</html>