Newer
Older
CarrotServer / src / servlet / RoomCreateServlet.java
t-nakanishi on 18 Jul 2017 1 KB [add] project
package servlet;

import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;

import room.RoomManager;

public class RoomCreateServlet extends  HttpServlet {
	
	// 受け取る部分							↓reqで受け取る           ↓respで返す
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, java.io.IOException {
		
		// RoomManagerを使うために宣言しておく                       ↓シングルトンパターンを利用しているため
		RoomManager roommgr = RoomManager.getInstance();
		
		// 返す文字の宣言 ↓返すためresp
		PrintWriter printwriter = resp.getWriter();
		
		/*******************************
		 *	パラメータを受け取る req
		 *******************************/
		String name = req.getParameter("name");
		String mode = req.getParameter("mode");
		String pass = req.getParameter("pass");
		String sId = req.getSession().getId();
		
		/*******************************
		 *	部屋の作成と、作成者を部屋に追加
		 *******************************/
		if(roommgr.createRoom(name, mode, pass, sId)) {
			printwriter.println("<result id = \"ok\">");
			System.out.println("-----RoomCreate OK-----");
			System.out.println("name: " + name);
			System.out.println("mode: " + mode);
			System.out.println("pass: " + pass);
		} else {
			printwriter.println("<result id = \"ng\">");	
			System.out.println("RoomCreate NG");
		}
		printwriter.println("</result>");	
		
	}
	
	// 返す部分(テスト用)
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, java.io.IOException {

		// 共有させることによってこちらだけで実効できる
		doPost(req, resp);

	}
}