설명 : getList.jsp는 게시글 목록을 보여주기 위해 사용되며, save.jsp는 새로운 게시글을 작성하여 게시글 목록에 추가하기 위해 사용.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>guestBook</display-name>
<welcome-file-list>
<welcome-file>template.jsp</welcome-file>
</welcome-file-list>
</web-app>
설명 :
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import = "java.util.*"%>
<%@ page import ="org.doo.Article" %>
<%
Vector<Article> list = (Vector<Article>) application.getAttribute("articleList");
if(list == null) {
list = new Vector<Article>();
application.setAttribute("articleList", list);
}
%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<form action ="save.jsp" method="post">
<table>
<tr>
<th>작성자</th>
<td><input type="text" name="writer"/></td>
</tr>
<tr>
<th>내용</th>
<td><input type="text" name="comment"/></td>
</tr>
<tr>
<th colspan="2">
<input type="submit" value="등록"/>
</th>
</tr>
</table>
</form>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ include file ="getList.jspf" %>
<table id="listTable">
<tr id = "header">
<th id="num">번호</th>
<th id="comment">내용</th>
<th id="writer">작성자</th>
<th id="date">작성일</th>
</tr>
<%
if(list.size() ==0){
%>
<tr>
<th colspan ="4">
empty
</th>
</tr>
<%
}
for(int i = list.size()-1; i>=0; i--) {
Article temp = list.get(i);
%>
<tr>
<th><%=i+1 %></th>
<th><%= temp.getComment() %></th>
<th><%= temp.getWriter() %></th>
<th><%= temp.getDate() %></th>
</tr>
<%
}
%>
</table>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ include file="getList.jspf" %>
<%
request.setCharacterEncoding("euc-kr");
String writer = request.getParameter("writer");
String comment = request.getParameter("comment");
Article article = new Article(writer, comment);
list.add(article);
response.sendRedirect(request.getContextPath());
%>
@charset "EUC-KR";
body {
text-align: center;
}
#mainBox {
margin: 0 auto;
border: 2px solid gray;
width: 80%;
}
tabel {
margin: 0 auto;
}
#listTable {
width: 80%;
border: 1px solid gray;
border-collapse: collapse;
}
#listTable td, #listTable th {
border: 1px solid gray;
}
#header {
background-color: #EEEEEE;
}
#num {
width: 10%
}
#comment {
width: 50%
}
#writer {
width: 20%
}
#top, #bottom {
margin: 1em;
}
input[type="text"] {
width: 20em;
}
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>guestBook</title>
<link href="css/main.css" rel="stylesheet" />
</head>
<body>
<h1>Guest Book</h1>
<div id="mainBox">
<div id="top">
<jsp:include page="write.jsp"/>
</div>
<hr>
<div id="bottom">
<jsp:include page="list.jsp" />
</div>
</div>
</body>
</html>
<결과>