comparison src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/ShowBoardsServlet.java @ 1:64a72a7a0491

add local bbs
author tatsuki
date Mon, 27 Jun 2016 04:24:25 +0900
parents
children
comparison
equal deleted inserted replaced
0:d04e3e9069aa 1:64a72a7a0491
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
8 public class ShowBoardsServlet extends HttpServlet
9 {
10 /**
11 *
12 */
13 private static final long serialVersionUID = 1L;
14 private final BulletinBoard bbs;
15 private final String createBoardPath;
16 private final String showBoardMessagePath;
17
18 public ShowBoardsServlet(BulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath)
19 {
20 bbs = _bbs;
21 createBoardPath = _createBoardPath;
22 showBoardMessagePath = _showBoardMessagePath;
23 }
24
25 public void doGet(HttpServletRequest _req,HttpServletResponse _res)
26 {
27 try{
28 _res.setCharacterEncoding("UTF-8");
29 printBoard(_res.getWriter());
30 }catch(Exception _e){
31 _res.setStatus(500);
32 }
33
34 }
35
36 private void printBoard(PrintWriter _pw) throws Exception
37 {
38 _pw.write("<html><body>\n");
39 _pw.write("<h1>BBS</h1>\n");
40 _pw.write("<form action='"+createBoardPath+"' method='POST'\n");
41 _pw.write("<p>Create new board.</p>");
42 _pw.write("<p>BoardName : <input type='text' name='bname'/></p>\n");
43 _pw.write("<p>Author : <input type='text' name='author'/> EditKey : <input type='text' name='key'/></p>\n");
44 _pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
45 _pw.write("<p><input type='submit' value='submit'/></p><hr/>\n");
46
47 _pw.write("<h2>list of boards</h2>");
48 for(String board : bbs.getBoards()){
49 _pw.write("<p><a href='"+showBoardMessagePath+"?bname=" + bbs.sanitize(board) + "'>"+ bbs.sanitize(board) + "</a></p>");
50 }
51
52 _pw.write("</body></html>");
53 _pw.flush();
54 }
55 }