2022年04月19日(火)
22310 ワード
Front Controller
BoardListController
BoardDetailController
BoardAddController
BoardUpdateController
BoardDeleteController
1つのサービスで複数のDAOを呼び出すこともできます
コントローラの制御を容易にするために、コントローラの共通コードを取り出してパッケージ化します.
=>
<<Front Controller>> DispatcherServlet
DispatcherServiceletにリクエストを送信します要求を受け取ったDispatcherServicelet
<<Page Controller>> BoardController
特定のページでのリクエストの処理ページコントローラを含める
<<Front Controller>> DispatcherServlet
•ページコントローラの汎用機能の実行‐異常処理
-ビュー構成部品の実行
‐入力値の検証
=>これがFront Controllerを作成する理由です
class + class + class = component
component + component = Framework
Framework + ⍺ = App.
クラスは構成部品であってもよい
例)抵抗->部品、チップ->部品
部品の最小単位
RAM... PCを個別に挿入できません
1つ以上のクラスからなる構成要素の典型的な例
component:1つ以上のクラスからなるミドルウェア
LinkedListは最も代表的なものです
ネストされたクラスを使用してノードというクラスを作成
2つのクラスを1つのロールに結合します.標準構成部品.
@SuppressWarnings("serial")

コールグリーン
お客様が何を求めているのか知りたいです.
Webブラウザに必要なリソース
htmlなら読んで投げてくれます.
単純ファイル、html、css、js、画像ファイルなどの静的リソースの場合は、直接読んでください.
実行が必要なリソースであれば、実行結果が投げ出されます.
urlはHTTPプロトコルの一部です
リクエストヘッダ情報抽出、url抽出方法を備えていない
実際にオブジェクトを渡してプロトコルへの応答を処理
クライアント要求を正しく処理するには、元のタイプを変更して使用します.
元のサービスを上書きするよりも、上書きする方が便利です.
GETリクエストを処理したいだけです
それはdoGetを超えています.
グリーンサービス黄色サービス
http://localhost:8080/app/board/list
@Override
protected void service(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println(request.getServletPath()); // /app
System.out.println(request.getPathInfo()); // /board/list
}
}
/app/board/list

urlが有効かどうかにかかわらず、返されます.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(request.getServletPath());
System.out.println(request.getPathInfo());
String controllerPath = request.getPathInfo();
RequestDispatcher 요청배달자 = request.getRequestDispatcher(controllerPath);
System.out.println(요청배달자);
요청배달자.include(request, response);
}
http://localhost:8080/app/board/list 無効なurlはエラーです
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(request.getServletPath());
System.out.println(request.getPathInfo());
String controllerPath = request.getPathInfo();
try {
RequestDispatcher 요청배달자 = request.getRequestDispatcher(controllerPath);
System.out.println(요청배달자);
요청배달자.include(request, response);
} catch (Exception e) { // 클라이언트가 보낸 url이 유효하지 않으면
request.setAttribute("exception", e);
request.getRequestDispatcher("/jsp/error.jsp").forward(request, response);
}
}

ハングル

includeはここでContent-typeを設定する必要があります
response.setContentType("text/html; charset=UTF-8");
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(request.getServletPath());
System.out.println(request.getPathInfo());
String controllerPath = request.getPathInfo();
try {
response.setContentType("text/html; charset=UTF-8");
RequestDispatcher 요청배달자 = request.getRequestDispatcher(controllerPath);
System.out.println(요청배달자);
요청배달자.include(request, response);
} catch (Exception e) { // 클라이언트가 보낸 url이 유효하지 않으면
request.setAttribute("exception", e);
request.getRequestDispatcher("/jsp/error.jsp").forward(request, response);
}
}
きれい
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(request.getServletPath());
System.out.println(request.getPathInfo());
String controllerPath = request.getPathInfo();
try {
response.setContentType("text/html; charset=UTF-8");
RequestDispatcher 요청배달자 = request.getRequestDispatcher(controllerPath);
System.out.println(요청배달자);
요청배달자.include(request, response);
Exception exception = (Exception) request.getAttribute("exception");
if (exception != null) { // 페이지 컨트롤러에서 에러가 발생한 경우
throw exception;
}
} catch (Exception e) { // 클라이언트가 보낸 url이 유효하지 않으면
if (request.getAttribute("exception") == null) {
request.setAttribute("exception", e);
}
request.getRequestDispatcher("/jsp/error.jsp").forward(request, response);
}
}
http://localhost:8080/app/board/list ページコントローラを通常クラスにする(POJO)
Page Controller
<<interface>> Controller
長所Front Controllerはすべてのリクエストを受信するため、ページコントローラはサーバである必要はありません.
サーブレットオブジェクトではないため、サーブレットコンテナは作成されません
このクラスのインスタンスは、サーブレットコンテナによって自動的に作成されません.
我々は創造しなければならない
いつですか.
サーバ起動時
ContextLoaderListener
ページコントロールはサーブレットではなくなりました
アニメーションおよび再生APIを使用したページコントローラオブジェクトの自動作成

Reference
この問題について(2022年04月19日(火)), 我々は、より多くの情報をここで見つけました https://velog.io/@banana/2022-04-19화テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol