1
|
1 package jp.ac.u_ryukyu.ie.cr.bbs.local;
|
|
2
|
|
3 import javax.servlet.http.HttpServlet;
|
|
4 import javax.servlet.http.HttpServletRequest;
|
|
5 import javax.servlet.http.HttpServletResponse;
|
|
6 import java.io.PrintWriter;
|
|
7 import java.util.Iterator;
|
|
8
|
|
9 public class ShowBoardMessageServlet extends HttpServlet {
|
|
10 /**
|
|
11 *
|
|
12 */
|
|
13 private static final long serialVersionUID = 1L;
|
|
14 private final BulletinBoard bbs;
|
|
15 private final String createBoardMessagePath;
|
|
16
|
|
17 private static final String PARAM_BOARD_NAME = "bname";
|
|
18
|
|
19 public ShowBoardMessageServlet(BulletinBoard _bbs, String _createBoardMessagePath, String _editMessagePath) {
|
|
20 bbs = _bbs;
|
|
21 createBoardMessagePath = _createBoardMessagePath;
|
|
22 }
|
|
23
|
|
24 public void doGet(HttpServletRequest _req, HttpServletResponse _res) {
|
|
25 String bname = _req.getParameter(PARAM_BOARD_NAME);
|
|
26
|
|
27 try {
|
|
28 printBoard(bname, _res.getWriter());
|
|
29 } catch (Exception _e) {
|
|
30 _res.setStatus(500);
|
|
31 }
|
|
32
|
|
33 }
|
|
34
|
|
35 private void printBoard(String _bname, PrintWriter _pw) throws Exception {
|
|
36 _pw.write("<html><body>\n");
|
|
37 _pw.write("<h1>" + bbs.sanitize(_bname) + "</h1>\n");
|
|
38
|
|
39 _pw.write("<form action='" + createBoardMessagePath + "' method='POST'\n");
|
|
40 _pw.write("<p>Author : <input type='text' name='author'/> <input type='hidden' name='bname' value='" + _bname + "'/> EditKey : <input type='text' name='key'/></p>\n");
|
|
41 _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
|
|
42 _pw.write("<p><input type='submit' value='submit'/></p>\n");
|
4
|
43 GetAttributeImp attribute = bbs.getAttribute(_bname, "[-1]", "-1");
|
1
|
44 Iterator<String> keys = attribute.getKeys();
|
|
45
|
4
|
46 do {
|
1
|
47 String key = keys.next();
|
|
48 String mesage = attribute.getMessage(key);
|
|
49 _pw.write("<p>" + key + " = " + mesage + "</p>\n");
|
4
|
50 } while (keys.hasNext());
|
1
|
51
|
|
52 _pw.write("</body></html>");
|
|
53 _pw.flush();
|
|
54 }
|
|
55 }
|