컨트롤러, 커맨드 구조 추가하여 연동
This commit is contained in:
11
hospital/src/main/java/command/Command.java
Normal file
11
hospital/src/main/java/command/Command.java
Normal 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;
|
||||
}
|
||||
14
hospital/src/main/java/command/HomeCommand.java
Normal file
14
hospital/src/main/java/command/HomeCommand.java
Normal 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";
|
||||
}
|
||||
}
|
||||
17
hospital/src/main/java/command/LoginCommand.java
Normal file
17
hospital/src/main/java/command/LoginCommand.java
Normal 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";
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,14 @@ version="3.1">
|
||||
|
||||
|
||||
<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>index.jsp</welcome-file>
|
||||
|
||||
21
hospital/src/main/webapp/home.jsp
Normal file
21
hospital/src/main/webapp/home.jsp
Normal 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>
|
||||
@@ -5,16 +5,8 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>병원 관리 시스템</title>
|
||||
<jsp:forward page="/home.do"></jsp:forward>
|
||||
</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>
|
||||
</BODY>
|
||||
</html>
|
||||
</html>
|
||||
Reference in New Issue
Block a user