comparison src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/browsing/ShowBoardsServlet.java @ 4:5acde010c6db

add jungle browsing system
author tatsuki
date Tue, 28 Jun 2016 19:45:55 +0900
parents src/main/java/jp/ac/u_ryukyu/ie/cr/bbs/local/ShowBoardsServlet.java@64a72a7a0491
children 2b3542c5be34
comparison
equal deleted inserted replaced
3:f3d30646c863 4:5acde010c6db
1 package jp.ac.u_ryukyu.ie.cr.bbs.browsing;
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 BrowsingBulletinBoard bbs;
15 private final String createBoardPath;
16 private final String showBoardMessagePath;
17
18 public ShowBoardsServlet(BrowsingBulletinBoard _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><input type='submit' value='submit'/></p><hr/>\n");
44
45 _pw.write("<h2>list of boards</h2>");
46 for(String board : bbs.getBoards()){
47 _pw.write("<p><a href='"+showBoardMessagePath+"?bname=" + bbs.sanitize(board) + "&path=-1" +"'>"+ bbs.sanitize(board) + "</a></p>");
48 }
49
50 _pw.write("</body></html>");
51 _pw.flush();
52 }
53 }