Struts1 ActionMappingの例の説明
この記事では主に Struts1 チュートリアルの ActionMapping を紹介します。編集者はそれを参考として共有します。エディターに従って見てみましょう
まず、ブレークポイントは processpath メソッドの外にあります
今日は、ActionMapping を取得する方法を見ていきます。メソッド---プロセスマッピング。 その前に、ActionMapping について簡単に説明します。ソース コードから、最も重要な属性は、主に対応する Struts のパス、type、forwardMap に似ていることがわかります。 config 設定ファイル。これは、この設定ファイルの情報をメモリに保存します。
特定の mvc small インスタンスの ActionMapping コードは次のとおりです:
package com.cjq.servlet; import java.util.Map; public class ActionMapping { private String path; private Object type; private Map forwardMap; public String getPath() { return path; } public void setPath(String path) { this.path = path; } public Object getType() { return type; } public void setType(Object type) { this.type = type; } public Map getForwardMap() { return forwardMap; } public void setForwardMap(Map forwardMap) { this.forwardMap = forwardMap; } }そして、Struts の Actionconfig のコード (ActionMapping はこの ActionConfig を継承するため、ActionConfig をより直接的に調べます) は次のとおりです:
ActionMapping の内容についていくつか説明したので、ActionMapping についてはある程度理解できたと思います。それでは、システムはどのように ActionMapping を生成し、どのようにして ActionMapping を見つけるのでしょうか?これが今日話したいことのすべてです:
Web で
/** * <p>Select the mapping used to process theselection path for this request * If no mapping can be identified, createan error response and return * <code>null</code>.</p> * * @param request The servlet request weare processing * @param response The servlet response weare creating * @param path The portion of the requestURI for selecting a mapping * * @exception IOException if an input/outputerror occurs */ protectedActionMapping processMapping(HttpServletRequestrequest, HttpServletResponse response, String path) throws IOException { // Is there a mapping for this path? ActionMapping mapping = (ActionMapping) moduleConfig.findActionConfig(path); // If a mapping is found, put it in the request and return it if (mapping != null) { request.setAttribute(Globals.MAPPING_KEY, mapping); return (mapping); } // Locate the mapping for unknown paths (if any) ActionConfig configs[] = moduleConfig.findActionConfigs(); for (int i = 0; i < configs.length; i++) { if (configs[i].getUnknown()) { mapping = (ActionMapping)configs[i]; request.setAttribute(Globals.MAPPING_KEY, mapping); return (mapping); } } // No mapping can be found to process this request String msg = getInternal().getMessage("processInvalid"); log.error(msg + " " + path); response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); return null; }まず、前のステップでインターセプトしたパスを渡し、moduleConfig の findAction メソッドで ActionConfig を検索し、ActionMapping を返します。具体的なコードは次のとおりです:
ActionMapping mapping =(ActionMapping) moduleConfig.findActionConfig(path);見つかった場合、ActionMapping はリクエストのコンテキストに保存されます。コード:
if (mapping != null) { request.setAttribute(Globals.MAPPING_KEY, mapping); return (mapping); }パスでマッピングが見つからない場合は、Actionconfig を走査して不明なパスのマッピングを見つけます。見つかった場合は、リクエストに保存されます。見つからない場合は、エラー メッセージが表示されます。具体的なコードは次のとおりです。
// Locate the mapping for unknownpaths (if any) ActionConfig configs[] = moduleConfigfindActionConfigs(); for (int i = 0; i < configslength; i++) { if (configs[i].getUnknown()) { mapping = (ActionMapping)configs[i]; request.setAttribute(Globals.MAPPING_KEY, mapping); return (mapping); } } // No mapping can be found to process this request String msg = getInternal().getMessage("processInvalid"); log.error(msg + " " + path); response.sendError(HttpServletResponse.SC_NOT_FOUND, msg); return null;文字列をインターセプトし、その文字列に基づいて ActionMapping を取得するときの processActionForm を見てみましょう (これは最初の 2 つで紹介されています)。記事)、ActionMapping を使用して ActionForm を作成し、その ActionForm をリクエストまたはセッションに入れて管理します。
/** * <p>Retrieve and return the <code>ActionForm</code> associatedwith * this mapping, creating and retaining oneif necessary. If there is no * <code>ActionForm</code> associated with this mapping,return * <code>null</code>.</p> * * @param request The servlet request weare processing * @param response The servlet response weare creating * @param mapping The mapping we are using */ protectedActionForm processActionForm(HttpServletRequestrequest, HttpServletResponse response, ActionMapping mapping) { // Create (if necessary) a form bean to use ActionForm instance = RequestUtilscreateActionForm (request, mapping, moduleConfig, servlet); if (instance == null) { return (null); } // Store the new instance in the appropriate scope if (log.isDebugEnabled()) { log.debug(" Storing ActionForm bean instance in scope '" + mapping.getScope() + "' under attribute key '" + mapping.getAttribute() + "'"); } if ("request".equals(mapping.getScope())) { request.setAttribute(mapping.getAttribute(), instance); } else { HttpSession session =requestgetSession(); session.setAttribute(mapping.getAttribute(), instance); } return (instance); }このメソッドの一般的なプロセスは次のとおりです: ActionMapping の名前に基づいて ActionForm を検索します。ActionForm が設定されている場合は、リクエストに進みます。またはセッションを検索すると、リクエストまたはセッション内に作成された ActionForm が存在する場合、それが返されます。存在しない場合は、ActionForm の完了パスに従ってリフレクションを使用して作成され、作成された ActionForm がリクエストまたはセッションに配置され、ActionForm が返されます。
// Create (if necessary) a formbean to use ActionForm instance = RequestUtils.createActionForm (request, mapping, moduleConfig, servlet); if (instance == null) { return (null); }RequestUtils.createActionForm メソッドを呼び出して、ActionMapping の ActionForm 文字列からオブジェクトを生成し、それを返します。次のコードを入力します:
publicstaticActionForm createActionForm( HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet) { // Is there a form bean associated with this mapping? String attribute = mappinggetAttribute(); if (attribute == null) { return (null); } // Look up the form bean configuration information to use String name = mapping.getName(); FormBeanConfig config =moduleConfigfindFormBeanConfig(name); if (config == null) { log.warn("No FormBeanConfig found under '"+ name + "'"); return (null); } ActionForm instance = lookupActionForm(request,attribute, mappinggetScope()); // Can we recycle the existing form bean instance (if there is one)? try { if (instance != null && canReuseActionForm(instance,config)) { return (instance); } } catch(ClassNotFoundException e) { log.error(servlet.getInternal().getMessage("formBean",config.getType()), e); return (null); } return createActionForm(config,servlet); }メソッドは、最初に変数名を定義し、インスタンスの LoginForm 文字列である String name = Mapping.getName(); から値を取得します。その後、FormBeanConfig config =moduleConfig.findFormBeanConfig(name); を呼び出すことにより、対応する LoginForm 文字列が対応するオブジェクトに生成されます。
<form-beans> <form-bean name="loginForm" type=".struts.LoginActionForm"/> </form-beans>
这个标签在服务器一启动的时候就会利用digester读取这里的配置信息,并且放在FormBeanConfig类中,这样我们可以通过上面那一句话就可以把LoginForm字符串生成相应的对象。
之后调用了ActionForm instance = lookupActionForm(request,attribute, mapping.getScope());这个方法,这个方法主要是查找scope属性中有没有存在ActionForm。具体实现:
if ("request".equals(scope)){ instance = (ActionForm)request.getAttribute(attribute); } else { session = request.getSession(); instance = (ActionForm)session.getAttribute(attribute); }
这里判断scope属性值是否为request,如果是则从request中读出ActionForm,如果不是则从session中读出。程序如果是第一次执行,那么ActionForm会是为空的。因为这里的ActionForm为空,所以就进入了if判断语句中,最后通过调用return createActionForm(config, servlet);创建ActionForm并且返回。
之后processActionForm就会把返回来的ActionForm放入request或者session中。具体实现就是:
if ("request".equals(mapping.getScope())){ request.setAttribute(mapping.getAttribute(), instance); } else { HttpSession session =request.getSession(); session.setAttribute(mapping.getAttribute(), instance); }
到此为止,ActionForm就创建完成,当ActionForm创建完成之后,就要用其他的方法来往ActionForm中赋值了
以上がStruts1 ActionMappingの例の説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undress AI Tool
脱衣画像を無料で

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

JDBCトランザクションを正しく処理するには、最初に自動コミットモードをオフにし、次に複数の操作を実行し、結果に応じて最終的にコミットまたはロールバックする必要があります。 1。CONN.SETAUTOCOMMIT(FALSE)を呼び出して、トランザクションを開始します。 2。挿入や更新など、複数のSQL操作を実行します。 3。すべての操作が成功した場合はconn.commit()を呼び出し、データの一貫性を確保するために例外が発生した場合はconn.rollback()を呼び出します。同時に、リソースを使用してリソースを管理し、例外を適切に処理し、接続を密接に接続するために、接続の漏れを避けるために使用する必要があります。さらに、接続プールを使用してセーブポイントを設定して部分的なロールバックを達成し、パフォーマンスを改善するためにトランザクションを可能な限り短く保つことをお勧めします。

仮想スレッドには、非常に並行したシナリオとIO集約型シナリオに大きなパフォーマンスの利点がありますが、テスト方法と適用可能なシナリオに注意を払う必要があります。 1.正しいテストでは、実際のビジネス、特にIOブロッキングシナリオをシミュレートし、JMHやガトリングなどのツールを使用してプラットフォームスレッドを比較する必要があります。 2。スループットのギャップは明らかであり、スケジューリングがより軽量で効率的であるため、100,000の同時リクエストよりも数倍から10倍高くなる可能性があります。 3。テスト中に、盲目的に高い並行性数を追求し、非ブロッキングIOモデルに適応し、レイテンシやGCなどの監視インジケーターに注意を払う必要があります。 4.実際のアプリケーションでは、Webバックエンド、非同期タスク処理、および多数の同時のIOシナリオに適していますが、CPU集約型タスクはプラットフォームスレッドまたはForkjoinpoolに依然として適しています。

tosetjava_homeonwindows、firstlocatethejdkinstallationpath(例:c:\ programfiles \ java \ jdk-17)、thencreateSystemenvironmentvaria blenamedjava_homewiththatpath.next、updatethepathvariablebyadding%java \ _home%\ bin、andverifythesetusingingingjava-versionandjavac-v

ServiceMeshは、Java Microservice Architectureの進化のための避けられない選択であり、その中心はネットワークロジックとビジネスコードの分離にあります。 1. ServiceMeshは、ビジネスに焦点を当てるために、サイドカーエージェントを介したロードバランシング、ヒューズ、監視、その他の機能を処理します。 2。ISTIO使節は中程度および大規模なプロジェクトに適しており、Linkerdは軽量で小規模な試験に適しています。 3. Java Microservicesは、発見とコミュニケーションのために、装い、リボン、その他のコンポーネントを閉鎖し、IStiodに引き渡す必要があります。 4.展開中にサイドカーの自動注入を確保し、トラフィックルールの構成、プロトコル互換性、ログトラッキングシステムの構築に注意を払い、増分移行とコントロール前の監視計画を採用します。

リンクリストを実装する鍵は、ノードクラスを定義し、基本操作を実装することです。 firstデータや次のノードへの参照を含むノードクラスを作成します。次に、LinkedListクラスを作成し、挿入、削除、および印刷機能を実装します。 deppentedメソッドは、テールにノードを追加するために使用されます。 printlistメソッドを使用して、リンクリストのコンテンツを出力します。 dreatewithValueメソッドは、指定された値を持つノードを削除し、ヘッドノードと中間ノードのさまざまな状況を処理するために使用されます。

サーバー側のテンプレートインジェクション(SSTI)の防止には、次の4つの側面が必要です。1。メソッド呼び出しの無効化やクラスの負荷の制限など、セキュリティ構成を使用します。 2.ユーザー入力はテンプレートコンテンツとして回避し、可変交換のみを避け、入力を厳密に検証します。 3.小石、口ひげ、レンダリングコンテキストなどのサンドボックス環境を採用します。 4.従属バージョンを定期的に更新し、コードロジックを確認して、テンプレートエンジンが合理的に構成されていることを確認し、ユーザー制御可能なテンプレートのためにシステムが攻撃されないようにします。

Java Collection Frameworkのパフォーマンスを向上させるために、次の4つのポイントから最適化できます。1。アレイリストへの頻繁なランダムアクセス、ハッシュセットへのクイック検索、同時環境の同時ハッシュマップなど、シナリオに従って適切なタイプを選択します。 2.初期化中に容量と荷重係数を合理的に設定して、容量の拡張オーバーヘッドを減らしますが、メモリ無駄を避けます。 3.不変のセット(list.of()など)を使用して、一定または読み取り専用データに適したセキュリティとパフォーマンスを改善します。 4.メモリの漏れを防ぎ、弱い参照またはプロのキャッシュライブラリを使用して、長期生存セットを管理します。これらの詳細は、プログラムの安定性と効率に大きく影響します。

setupamaven/gradleprojectwithjax-rsdependencieslikejersey; 2.createarestresourceingnotationssuchas@pathand@get; 3.configuretheapplicationviaapplicationubclassorweb.xml;
