| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- controller
- DevOps
- Cloud
- backend
- HTTP
- 프롬프트
- NOTE
- command
- Framework
- jsp
- usecasediagram
- MVC
- Program
- ERD
- handlerMapping
- system developer
- 맥린이
- Agile
- tiles
- pattern
- mybatis
- classdiagram
- getAttribute
- UML
- FrontController
- Spring
- 내장객체
- setAttribute
- getParameter
- App
Archives
- Today
- Total
시작은 언제라도
2. FrontControllerServlet ex2 본문
public void handleRequest(request.getParameter("command");
if(command.equals("FindCar")) {
findCar(request, response);
}else if(command.equals("RegisterCar")){
RegisterCar(request, response);
}
}
//차 정보 검색 메서드
public void findCar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String carNo = request.getParameter("carNo");
String carInfo = MockDAO.getInstance().findCarInfo(carNo);
String view = null;
if(carInfo==null) {
view= "findcar-fail.jsp";
}else {
view="findcar-ok.jsp";
request.setAttribute("carInfo", carInfo);
}
request.getRequestDispatcher(view).forward(request, response);
}
//차 등록 메서드
public void RegisterCar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String carInfo = request.getParameter("carInfo");
MockDAO.getInstance().registerCar(carInfo);
response.sendRedirect("registercar-result.jsp");
}
//handleRequest 메서드로 hidden값(command)를 받아와서 해당하는 경우에 알맞는 메서드로 command값을 보내준다.
//command가 FindCar과 같다면, findCar메서드에 command값(carNo)를 보내주고,
//command가 RegisterCar와 같다면 registerCar메서드에 command값(carInfo)를 보내준다.
'Web programming > Patterns' 카테고리의 다른 글
| Command Design Pattern (0) | 2021.04.18 |
|---|---|
| 3. FrontControllerServlet ex3 (0) | 2021.04.18 |
| 1. FrontControllerServlet ex1 (0) | 2021.04.18 |
| Design Pattern 이란? (0) | 2021.04.18 |
| FrontController Pattern - 1 (0) | 2021.04.18 |