38
|
1 package jungle.test.bbs;
|
|
2
|
|
3 import java.io.PrintWriter;
|
|
4
|
|
5 import javax.servlet.http.HttpServlet;
|
|
6 import javax.servlet.http.HttpServletRequest;
|
|
7 import javax.servlet.http.HttpServletResponse;
|
|
8
|
|
9 public class ShowBoardMessageServlet extends HttpServlet
|
|
10 {
|
|
11 /**
|
|
12 *
|
|
13 */
|
|
14 private static final long serialVersionUID = 1L;
|
|
15 private final BulletinBoard bbs;
|
|
16 private final String createBoardMessagePath;
|
|
17 private final String editMessagePath;
|
|
18
|
|
19 private static final String PARAM_BOARD_NAME = "bname";
|
|
20
|
|
21 public ShowBoardMessageServlet(BulletinBoard _bbs,String _createBoardMessagePath, String _editMessagePath)
|
|
22 {
|
|
23 bbs = _bbs;
|
|
24 createBoardMessagePath = _createBoardMessagePath;
|
|
25 editMessagePath = _editMessagePath;
|
|
26 }
|
|
27
|
|
28 public void doGet(HttpServletRequest _req,HttpServletResponse _res)
|
|
29 {
|
|
30 String bname = _req.getParameter(PARAM_BOARD_NAME);
|
|
31
|
|
32 try{
|
|
33 printBoard(bname,_res.getWriter());
|
|
34 }catch(Exception _e){
|
|
35 _res.setStatus(500);
|
|
36 }
|
|
37
|
|
38 }
|
|
39
|
|
40 private void printBoard(String _bname,PrintWriter _pw) throws Exception
|
|
41 {
|
|
42 _pw.write("<html><body>\n");
|
|
43 _pw.write("<h1>"+_bname+"</h1>\n");
|
|
44
|
|
45 _pw.write("<form action='"+createBoardMessagePath+"' method='POST'\n");
|
|
46 _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='"+_bname+"'/> EditKey : <input type='text' name='key'/></p>\n");
|
|
47 _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
|
|
48 _pw.write("<p><input type='submit' value='submit'/></p>\n");
|
|
49
|
|
50 for(BoardMessage msg : bbs.getMessages(_bname)){
|
|
51 _pw.write("<hr/>");
|
|
52 _pw.write("<p><b>"+msg.getAuthor()+"</b></p>");
|
|
53 _pw.write("<p>"+msg.getMessage()+"</p>");
|
|
54 _pw.write("<small><a href='"+editMessagePath+"?bname="+_bname+"&uuid="+msg.getUUID()+"'>edit</a></small>");
|
|
55 }
|
|
56
|
|
57 _pw.write("</body></html>");
|
|
58 _pw.flush();
|
|
59 }
|
|
60 }
|