diff src/main/java/jungle/app/bbs/ShowBoardsServlet.java @ 105:f9e29a52efd3

Move some files
author one
date Tue, 26 Nov 2013 06:43:10 +0900
parents src/jungle/app/bbs/ShowBoardsServlet.java@29127ac788a6
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jungle/app/bbs/ShowBoardsServlet.java	Tue Nov 26 06:43:10 2013 +0900
@@ -0,0 +1,55 @@
+package jungle.app.bbs;
+
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class ShowBoardsServlet extends HttpServlet
+{
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private final BulletinBoard bbs;
+	private final String createBoardPath;
+	private final String showBoardMessagePath;
+
+	public ShowBoardsServlet(BulletinBoard _bbs, String _createBoardPath,String _showBoardMessagePath)
+	{
+		bbs = _bbs;
+		createBoardPath = _createBoardPath;
+		showBoardMessagePath = _showBoardMessagePath;
+	}
+	
+	public void doGet(HttpServletRequest _req,HttpServletResponse _res)
+	{
+		try{
+			printBoard(_res.getWriter());
+		}catch(Exception _e){
+			_res.setStatus(500);
+		}
+		
+	}
+	
+	private void printBoard(PrintWriter _pw) throws Exception
+	{
+		_pw.write("<html><body>\n");
+		_pw.write("<h1>BBS</h1>\n");
+		_pw.write("<form action='"+createBoardPath+"' method='POST'\n");
+		_pw.write("<p>Create new board.</p>");
+		_pw.write("<p>BoardName : <input type='text' name='bname'/></p>\n");
+		_pw.write("<p>Author : <input type='text' name='author'/> EditKey : <input type='text' name='key'/></p>\n");
+		_pw.write("<p>Message<br/> <input type='textarea' name='msg'/> </p>\n");
+		_pw.write("<p><input type='submit' value='submit'/></p><hr/>\n");
+		
+		_pw.write("<h2>list of boards</h2>");
+		for(String board : bbs.getBoards()){
+			_pw.write("<p><a href='"+showBoardMessagePath+"?bname="+board+"'>"+board+"</a></p>");
+		}
+		
+		_pw.write("</body></html>");
+		_pw.flush();
+	}
+}