> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/mvc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/mvc/4.-mvc/view-v2.md).

# View 분리 - v2

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

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

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

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

![](https://4059345879-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MdtAbfiAnzkPUNovpHX%2F-Me-RexZp1im8pOLJxnV%2F-Me-S35xdfz7qgAkIIpV%2FScreen%20Shot%202021-07-07%20at%207.11.56%20PM.png?alt=media\&token=5d171d27-71cf-4652-a55e-f8a63061f375)

구현에 있어 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;

}

```
