# View 분리 - v2

모든 컨트롤러에서 뷰로 이동하는 부분에 중복이 있고, 깔끔하지 않다.\
\=> 별도로 뷰를 처리하는 객체를 만들자.

```java
 String viewPath = "/WEB-INF/views/new-form.jsp";
  RequestDispatcher dispatcher = request.getRequestDispatcher(viewPath);
  dispatcher.forward(request, response);
```

이제 컨트롤러가 View생성하고 반환한다.

View를 인터페이스로 설계하게 되면 . 확장성 좋게 JSP 뿐만아니라 다른 포맷의 데이터들도 반환이 가능하게 된다!

![](/files/-Me-S35xdfz7qgAkIIpV)

구현에 있어 Controller2와 달라진 점\
Controlleer2는 MyView를 생성하고 반환만 한다!

```java
package hello.servlet.web.frontcontroller.v2;

import hello.servlet.web.frontcontroller.MyView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public interface ControllerV2 {
    //ControllerV2는 MyView를 생성하고 반환만 한다!
    MyView process(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException;

}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/mvc/4.-mvc/view-v2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
