일단
개인적으로 생각하는 가장 큰 MVC 와 MVC2의 차이를 예를 든다면
기본적으로 Controller 에서 더욱 Controller 역할하고
View 에선 더욱 View 적인 역할을 한다.
예를 들면
// 아래 글은 Head First Servlets/JSP 발췌 내용이다
// 아래 내용은 MVC 패턴 ( 아래 내용은 Controller 와 View 역할을 동시에 진행하고 있다.)
public class Ch1Servlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
PrintWriter out = response.getWriter();
Date today = new Date();
out.print(
"<html>" + "<body>" + "<h1 align=center>HF\'s Chapter1 Servlet</h1>"
+ "<br>" + today + "</body>" + "</html>"
);
}
}
위에서 실제로 필요한 데이터는 today 이다.
MVC2 로 넘어가게되면
public class Ch1Servlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
Date today = new Date();
request.setAttribute("today", today);
RequestDispatcher view =
request.getRequestDispatcher("testIndex.jsp");
view.forward(request, response);
}
}
위의 코드와 같이 변경할 수 있으며 today 정보만 setAttribute 하여 HTML 에서 사용할수 있도록 한다.
예로든 testIndex.jsp 에서는
<html>
<body>
<h1 align=center>HF's Chapter1 Servlet</h1><br/>
today
</body>
</html>
이와 같이 변경될 것이다. View 는 항상 변경이 될때마다 Servlet 을 컴파일하는 수고를 줄일수 있다.
today 데이터는 그대로 존재하지만 View 그래도의 View 만 변경할 수 있도록 한다.
MVC2 로 넘어가게되면
모델1 (MVC)
모델 1 구조 정리 |
- 정의 : 모든 클라이언트 요청과 응답을 JSP가 담당하는 구조이다. |
모델2 (MVC2)
모델 2 구조 정리 |
- 정의 : 클라이언트의 요청처리와 응답처리, 비즈니스 로직 처리하는 부분을 모듈화시킨 구조이다. |
이미지 출처 - [http://changhozz.tistory.com/126]
'Java' 카테고리의 다른 글
Java 배열 선언 (0) | 2015.07.13 |
---|---|
JAVA 접근지정자(Access modifier) (0) | 2015.07.13 |
자바의 초기화 블록 (0) | 2015.07.09 |
Java 초기화 이유 (0) | 2015.07.08 |
List Key 이용하여 추출하기 (0) | 2014.05.09 |