annotate src/jungle/test/bbs/ShowBoardMessageServlet.java @ 38:d8ee57a1c2c6

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