comparison src/main/java/app/bbs/ShowBoardsServlet.java @ 112:8f9811a1e00c

Moved app files
author one
date Fri, 29 Nov 2013 04:31:22 +0900
parents src/main/java/jungle/app/bbs/ShowBoardsServlet.java@f9e29a52efd3
children
comparison
equal deleted inserted replaced
111:6e7724d55a72 112:8f9811a1e00c
1 package app.bbs;
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 public class ShowBoardsServlet extends HttpServlet
10 {
11 /**
12 *
13 */
14 private static final long serialVersionUID = 1L;
15 private final BulletinBoard bbs;
16 private final String createBoardPath;
17 private final String showBoardMessagePath;
18
19 public ShowBoardsServlet(BulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath)
20 {
21 bbs = _bbs;
22 createBoardPath = _createBoardPath;
23 showBoardMessagePath = _showBoardMessagePath;
24 }
25
26 public void doGet(HttpServletRequest _req,HttpServletResponse _res)
27 {
28 try{
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="+board+"'>"+board+"</a></p>");
50 }
51
52 _pw.write("</body></html>");
53 _pw.flush();
54 }
55 }