MVC とは何かを簡単に見てみましょう。
MVC(Mode-view-controller )
その名前が示すように、ソフトウェア アーキテクチャ パターンは、アプリケーションにhave its Model Classes (i.e domain models / DTOs) views (i.e can be JSP, JSON etc) and controller (i.e Servlet) to be as modularized as possible so that it encourages re-usability, loose-coupling between the different layers and Seperation of Concerns
.
したがって、この背後にある重要なアイデアはencourage Seperation of Concerns
.
Say i want to change the view from JSP to freemarker view , if MVC is tighly followed , i should be able to accomplish the change with minimum to no impact to Controller layer (i.e Servlets)
これは、私の webapp でレイヤーが明確に分離されている場合にのみ実現できます。
If i had just scattered all the functions without regard to MVC like having views generated from the Servlet, or making service level calls like accessing the DB directly from the Controller etc is bad because any change in the view or the Database layer will cause massive changes at the Servlet .
あなたの質問に答えるために、your servlet should not directly produce the HTML output
.
Store all the objects
ビューを生成しin Request Attribute
、access it in JSP
Sevlet を再コンパイルすることは、 MVC に従わないという意味ではありません。MVC に従うことで、変更が最小限になり、1 つの場所にグループ化されるだけです。
ここでは、JSON の概念を削除し、わかりやすくシンプルにします このチュートリアルを進めてください。きちんとした MVC を実現する方法がかなり説明されています。
Jsp MVC チュートリアル。
を把握したら、JSON、AJAX、Asynchronous Request などのより複雑なものをいつでも追加できます。