컨트롤러, 커맨드 구조 추가하여 연동

This commit is contained in:
mcutegs2
2020-06-08 16:50:52 +09:00
parent 70c7c4771a
commit 831a4a2d5e
7 changed files with 125 additions and 10 deletions

View File

@@ -0,0 +1,11 @@
package command;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface Command {
public String exec(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException;
}

View File

@@ -0,0 +1,14 @@
package command;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HomeCommand implements Command {
public String exec(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
return "home.jsp";
}
}

View File

@@ -0,0 +1,17 @@
package command;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginCommand implements Command {
@Override
public String exec(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//TODO : DB작업 필요
return "views/student/loginForm.jsp";
}
}

View 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);
}
}

View File

@@ -8,6 +8,14 @@ version="3.1">
<display-name>Archetype Created Web Application</display-name> <display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>FrontController</servlet-name>
<servlet-class>controller.Fcontroller</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FrontController</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list> <welcome-file-list>
<welcome-file>index.jsp</welcome-file> <welcome-file>index.jsp</welcome-file>

View File

@@ -0,0 +1,21 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>what the hell?</h1>
</body>
<BODY bgcolor=black>
<h1 style="color:white;">병원 임직원 회원가입</h1>
<font color=white>
아이디 : <INPUT type="text" name="id" maxlength="8"><BR>
암호 : <INPUT type="password" name="pwd" maxlength="8"><BR>
이름 : <INPUT type="text" name="name" maxlength="12"><BR>
e-mail : <INPUT type="text" name="email" maxlength="25"><P>
<INPUT type="submit" value=" 저 장 "></font>
</body>
</html>

View File

@@ -5,16 +5,8 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>병원 관리 시스템</title> <title>병원 관리 시스템</title>
<jsp:forward page="/home.do"></jsp:forward>
</head> </head>
<BODY bgcolor=black>
<h1 style="color:white;">병원 임직원 회원가입</h1>
<FORM action="join.jsp" method="post">
<font color=white>
아이디 : <INPUT type="text" name="id" maxlength="8"><BR>
암호 : <INPUT type="password" name="pwd" maxlength="8"><BR>
이름 : <INPUT type="text" name="name" maxlength="12"><BR>
e-mail : <INPUT type="text" name="email" maxlength="25"><P>
<INPUT type="submit" value=" 저 장 "></font>
</FORM> </FORM>
</BODY> </BODY>
</html> </html>