컨트롤러, 커맨드 구조 추가하여 연동
This commit is contained in:
52
hospital/src/main/java/controller/Fcontroller.java
Normal file
52
hospital/src/main/java/controller/Fcontroller.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import command.Command;
|
||||
import command.HomeCommand;
|
||||
import command.LoginCommand;
|
||||
|
||||
@WebServlet("/Fcontroller")
|
||||
public class Fcontroller extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
HashMap<String, Command> list = null;
|
||||
public Fcontroller() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
// TODO Auto-generated method stub
|
||||
list = new HashMap<String, Command>();
|
||||
|
||||
list.put("/login.do", new LoginCommand()); //로그인 처리
|
||||
list.put("/home.do", new HomeCommand()); //처음 보여주는 페이지;
|
||||
//이 부분에 계속적으로 매핑을 추가하면 됨
|
||||
|
||||
}
|
||||
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
// TODO Auto-generated method stub
|
||||
request.setCharacterEncoding("utf-8");
|
||||
String uri = request.getRequestURI();
|
||||
|
||||
String contextPath = request.getContextPath();
|
||||
String path = uri.substring(contextPath.length());
|
||||
Command comm = list.get(path);
|
||||
String view = comm.exec(request, response);
|
||||
|
||||
RequestDispatcher dispatcher = request.getRequestDispatcher(view);
|
||||
dispatcher.forward(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user