|
NEW
次世代WebDB開発言語Alinous-Core
ほぼHTMLとSQLだけでアプリケーション開発。
EclipseプラグインによるGUIデバッガ搭載
今すぐ無料ダウンロード

CROSSFIRE O/R
無料ダウンロード
WEB+DB PRESS VOL.27
にBlastJ紹介記事連載掲載がスタートしました。 |
SoftwareDesign2005年6月号
にBlastJ紹介記事が掲載されました。 |
JavaWorld2005年5月号のNews & ProductsのコーナーでBlastJが紹介されました |
SIパートナー |
 |
|
|

|
業界TOPクラスのJavaエキスパートによる一括請負サービスを提供いたします。
採用のページはこちら。 |
|
|
|
RequestProcessorはStrutsのほぼ本体
RequestProcessorとは、リクエストを処理するためのオブジェクトです。
ある意味、そのままなのだが、よりStrutsフレームワークを扱い、拡張する上で知っておくと安心してつかえるので、Strutsの多少ソースコードも見ながら説明します。
ソースコードの中のRequestProcessor
通常、JavaでWebプログラミングを行う場合には、Servletオブジェクトを実装します。これは、Strutsでも同じで、StrutsではActionServletというクラスを実装します。
その中の、doGet()、doPost()メソッドを見てみましょう。
ActionServlet.java |
(前略)
public class ActionServlet extends HttpServlet {
(中略)
/**
* <p>The <code>RequestProcessor</code> instance we will use to process
* all incoming requests.</p>
*
* @since Struts 1.1
*/
protected RequestProcessor processor = null;
(中略)
/**
* <p>Process an HTTP "GET" request.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
process(request, response);
}
/**
* <p>Process an HTTP "POST" request.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
process(request, response);
}
(中略)
}
|
両方とも、自身のprocess()メソッドに処理を丸投げしています。
では、同じクラス(ファイル)にprocess()メソッドの実装がありますので見てみましょう。
ActionServlet.java |
(前略)
public class ActionServlet extends HttpServlet {
(中略)
/**
* <p>Perform the standard request processing for this request, and create
* the corresponding response.</p>
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception is thrown
*/
protected void process(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
ModuleUtils.getInstance().selectModule(request, getServletContext());
ModuleConfig config = getModuleConfig(request);
RequestProcessor processor = getProcessorForModule(config);
if (processor == null) {
processor = getRequestProcessor(config);
}
// ここがすべて!
processor.process(request, response);
}
(中略)
}
|
コメントで「ここがすべて!」と書いてありますが、本当にここがすべてです。
では、それより前のコードは何かと申しますと、processorオブジェクトを取得するための処理です。コンフィグファイルの状況で場合わけして、processorオブジェクトのインスタンスを取得しています。
なお、processerにどのクラスのオブジェクトを使うかは、struts-config.xmlの中で次のように指定できます。
この例では「org.apache.struts.tiles.TilesRequestProcessor」クラスを指定しています。
struts-config.xml |
<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
|
|