시작은 언제라도

FrontController Pattern - 1 본문

Web programming/Patterns

FrontController Pattern - 1

row_a_boat 2021. 4. 18. 16:03

findcar-form.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>차정보 조회-form</title>
</head>
<body>
<%--
			jsp -- FrontControllerServlet --Model
							|
							findcar-ok.jsp
							findcar-fail.jsp
--%>
<form action="FrontControllerServlet">
<input type="hidden" name="command" value="FindCar">
차번호 <input type="number" required="required" name="carNo">
<input type="submit" value="검색">
</form>
</body>
</html>

차정보 조회 form.jsp에서 FrontControllerServlet으로 차번호(CarNo)와 hidden command(FindCar)을 보낸다.

 

FrontControllerServlet.java

package org.kosta.webstudy17.controller;

import java.io.IOException;
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 org.kosta.webstudy17.model.MockDAO;

@WebServlet("/FrontControllerServlet")
public class FrontControllerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public FrontControllerServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		handleRequest(request,response);
		
	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		handleRequest(request,response);

	}

 

FrontControllerServlet의 나머지 코드는 뒤의 예제들에서 찾아보자

 

'Web programming > Patterns' 카테고리의 다른 글

Command Design Pattern  (0) 2021.04.18
3. FrontControllerServlet ex3  (0) 2021.04.18
2. FrontControllerServlet ex2  (0) 2021.04.18
1. FrontControllerServlet ex1  (0) 2021.04.18
Design Pattern 이란?  (0) 2021.04.18