위로
아래
String command = null;
String page = null;
if(request.getParameter("command")==null)
command="list";
else command = request.getParameter("command");
switch(command) {
case "list" : {
page = "action/BoardList.jsp";
break;
}
case "writeForm" : {
page = "view/BoardWriteForm.jsp";
break;
}
case "writeAction" : {
page = "action/BoardWriteAction.jsp";
break;
}
default : {
page = "view/Error.jsp";
break;
}
}
RequestDispatcher dp = request.getRequestDispatcher(page);
dp.forward(request, response);
}
전체
더보기
package controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class BoardController
*/
@WebServlet("/jb")
public class BoardController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public BoardController() {
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String command = null;
String page = null;
if(request.getParameter("command")==null)
command="list";
else command = request.getParameter("command");
switch(command) {
case "list" : {
page = "action/BoardList.jsp";
break;
}
case "writeForm" : {
page = "view/BoardWriteForm.jsp";
break;
}
case "writeAction" : {
page = "action/BoardWriteAction.jsp";
break;
}
default : {
page = "view/Error.jsp";
break;
}
}
RequestDispatcher dp = request.getRequestDispatcher(page);
dp.forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
/* 얘 안 쓴다.
private void doPro(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// controller 역할
// MVC 아키텍쳐 스타일을 기본으로 추가해서 작성
// controller : 화면에서 url을 받아서 해당 비즈니스 로직으로 보내고 리턴으로 view를 받는다.
// Model : 데이터 전송 오브젝트(DTO), 데이터 접근 오브젝트(DAO)
// View : 화면을 출력하는 것으로 사용자와 접속하는 인터페이스 (jsp)
String command = request.getParameter("command");
System.out.println(command);
String view="./view/BoardWriteForm.jsp";
switch(command) {
case "BList":{
//게시판 글을 읽어와서 저장하는 처리
//foward로 해당 페이지로 보내서 주소는 변경 X
view = "./view/BoradList.jsp";
}
case "BWriteForm":{
view = "./view/BoardWriteForm.jsp";
}
RequestDispatcher rd = request.getRequestDispatcher(view);
try {
rd.forward(request, response);
} catch (ServletException | IOException e) {
e.printStackTrace();
}
}
}
*/
}