comparison src/main/java/app/bbs/thinks/ShowBoardsServletMatrix.java @ 190:269bada9eedc

add
author tatsuki
date Fri, 17 Oct 2014 15:16:56 +0900
parents
children
comparison
equal deleted inserted replaced
189:8788cc341358 190:269bada9eedc
1 package app.bbs.thinks;
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 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.bbs.BulletinBoard;
10
11 public class ShowBoardsServletMatrix extends HttpServlet
12 {
13 /**
14 *
15 */
16 private static final long serialVersionUID = 1L;
17 private final BulletinBoard bbs;
18 private final String createBoardPath;
19 private final String showBoardMessagePath;
20
21 public ShowBoardsServletMatrix(BulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath)
22 {
23 bbs = _bbs;
24 createBoardPath = _createBoardPath;
25 showBoardMessagePath = _showBoardMessagePath;
26 }
27
28 public void doGet(HttpServletRequest _req,HttpServletResponse _res)
29 {
30 try{
31 _res.setCharacterEncoding("UTF-8");
32 printBoard(_res.getWriter());
33 }catch(Exception _e){
34 _res.setStatus(500);
35 }
36
37 }
38
39 private void printBoard(PrintWriter _pw) throws Exception
40 {
41 _pw.write("<html><body>\n");
42 _pw.write("<h1>BBS</h1>\n");
43 _pw.write("<form action='"+createBoardPath+"' method='POST'\n");
44 _pw.write("<p>Create new board.</p>");
45 _pw.write("<p>BoardName : <input type='text' name='bname'/></p>\n");
46 _pw.write("<p>Author : <input type='text' name='author'/> 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><hr/>\n");
49
50 _pw.write("<h2>list of boards</h2>");
51 for(String board : bbs.getBoards()){
52 _pw.write("<p><a href='"+showBoardMessagePath+"?bname=" + bbs.sanitize(board) + "'>"+ bbs.sanitize(board) + "</a></p>");
53 }
54
55 _pw.write("</body></html>");
56 _pw.flush();
57 }
58 }