<?xml version="1.0" encoding="Shift_JIS" ?>
<document url="./works.xml">
<properties>
<author>Anthony Kay</author>
<title>How Does Struts Work? - Apache Struts</title>
	<translator>高見沢 徳明</translator> 
	<editor>高橋 達男</editor> 
    <status>completion</status>
	<update>2005/04/08</update>
</properties>
<body>
<primary>
<chapter href="faq" name="How does Struts work?" />
</primary>
<chapter href="faq" name="Struts はどのように動くのか？">

<primary>
<section href="how" name="How does Struts work?">
</section>
</primary>
<section href="how" name="Struts はどのように動くのか？">

<primary>
<p>
    Java Servlets are designed to handle requests made by Web browsers.
    Java ServerPages are designed to create dynamic Web pages that can turn billboard sites into live applications.
    Struts uses a special Servlet as a switchboard to route requests from Web browsers to the appropriate ServerPage.
    This makes Web applications much easier to design, create, and maintain.
</p>
</primary>
<p>
	JavaサーブレットはWebブラウザが送信するリクエストを扱うようにデザインされています。
	JSP(Java ServerPages)は動的なWebページを生成するようにデザインされており、
	そのページは変化のないサイトを変化のあるアプリケーションに変えます。
	StrutsはWebブラウザからのリクエストを適切なServerPageに中継する交換台として、
	特別なサーブレットを使用します。
	これがWebアプリケーションの設計、構築、管理を非常に容易にしてくれます。
</p>
<note>billboard site, live applicationは意訳しています(高橋)</note>

<primary>
<p>
    Here is some more detail on the mechanisms and dependencies of Struts:
</p>
</primary>
<p>
	Strutsのメカニズムと依存関係について詳しく説明します。
</p>

<ul>
<primary>
   <li>
      The web application that you develop has a deployment descriptor
      (<code>WEB-INF/web.xml</code>) which you must write. This file describes
      the configuration of your web application, including welcome pages (the
      file that is shown in a directory when none is specified by the request),
      mappings to servlets (path or extension name), and parameters to those
      servlets.<br/>

      In this file, you configure the Struts
      <a href="../api/org/apache/struts/action/ActionServlet.html"><code>ActionServlet</code></a>
      as the servlet that will handle all requests for a given mapping (usually
      the extension <code>.do</code>). This is the "switchboard" mentioned
      above.<br/>

      In this same file, you configure the <code>ActionServlet</code> to use
      one or more configuration files for Struts itself.<br/>
      For this text, assume we are installing the web application on the server
      at <code>/myapp</code>, and are using the simplest possible configuration
      from there.<br/>

      If you need more details on deployment descriptors, read
      the Servlet Specification available from Sun Microsystem's
      <a href="http://java.sun.com">Java site</a>.<br/>
   </li>
</primary>
   <li>
		Webアプリケーションを開発する場合、デプロイメント記述子 (<code>WEB-INF/web.xml</code>)
		を必ず作成しなければなりません。
		このファイルには開発するWebアプリケーションの設定が記述されています。
		設定としては、ウェルカムページ（リクエストでファイル名が指定されない場合にディレクトリ上に表示されるファイル）、
		サーブレット（パスや拡張子名）へのマッピング、それらのサーブレットへのパラメータなどがあります。<br/>

		このファイルで、指定したマッピング（通常、<code>.do</code>という拡張子）
		への全てのリクエストを扱うサーブレットとして、Strutsの
		<a href="../api/org/apache/struts/action/ActionServlet.html"><code>ActionServlet</code></a>
		を設定します。これが上に述べた「交換台」です。<br/>

		同じファイルで、Struts内部で1つまたは複数の設定ファイルを使うように
		<code>ActionServlet</code> を設定します。<br/>
		このページの説明では、Webアプリケーションをサーバの<code>/myapp</code>にインストールし、
		そこから可能な限り最も単純な設定を使用していると仮定しています。<br/>

		デプロイメント記述子の詳細を知る必要がありましたら、
		Sun Microsystemsの<a href="http://java.sun.com">Java サイト</a>に
		サーブレット仕様がありますのでそちらをご利用下さい。<br/>
   </li>
<primary>
   <li>
      In the Struts configuration file(s), you associate paths with
      the controller components of your application, known as
      <a href="../api/org/apache/struts/action/Action.html"><code>Action</code></a>
      classes (i.e. "login" ==&gt; LoginAction class). This tells the Struts
      <code>ActionServlet</code> that when the incoming request is
      <code>http://myhost/myapp/login.do</code> it should invoke your
      controller component <code>LoginAction</code>.<br/>

      Note the extension <code>.do</code> in this URL. The extension causes
      your container (i.e.  Tomcat) to call the <code>ActionServlet</code>,
      which sees the word "login" as the thing you want to do. The
      configuration is referenced, and your <code>LoginAction</code> is
      executed.<br/>
   </li>
</primary>
   <li>
		(1つまたは複数の)Struts設定ファイルで、アプリケーションのコントローラコンポーネントにパスを関連づけます。
		このコンポーネントは <a href="../api/org/apache/struts/action/Action.html"><code>Action</code></a>
		クラスとして知られています(例: "login" ==&gt; LoginAction クラス)。
		この方法で、届いたリクエストが<code>http://myhost/myapp/login.do</code>の時にコントローラコンポーネントである
		<code>LoginAction</code>を呼び出すように、Strutsの<code>ActionServlet</code>に伝えるのです。<br/>

		このURLの中の<code>.do</code>拡張子に注意してください。この拡張子をつけると、
		あなたの使用しているコンテナ（例: Tomcat）は<code>ActionServlet</code>を呼び出します。
		<code>ActionServlet</code>は"login"という単語をあなたの行いたいことと見なします。
		この設定を参照し、<code>LoginAction</code>を実行します。<br/>
   </li>
<primary>
   <li>
      For each <code>Action</code>, you also configure Struts with the names of
      the resulting page(s) that can be shown as a result of that action. There
      can be more than one view as the result of an action (often, there are at
      least two: one for success, and one for failure).<br/>

      Your <code>Action</code> (the controller component you write) is based on
      these <em>logical</em> result mapping names. It reports back to the
      <code>ActionServlet</code> using words like "success", "failure",
      "ready", "ok", "UserIsIncompetent", etc.  The Struts system (through the
      configuration that you wrote) knows how to forward to the proper
      <em>specific</em> page. This has the added advantage of reconfiguration of
      the view layer by simply editing the Struts XML configuration file.<br/>

      At this point Struts knows how to delegate to your controller components,
      and what to show as a result of your controller processing. The "model"
      part of the application is completely up to you, and is called from
      within your controller components.
   </li>
</primary>
   <li>
		Strutsでは、<code>Action</code>ごとにアクションの結果として表示されるページの名前も設定します。
		アクションの結果として複数のビューが出力されるはずです（たいていの場合、少なくとも2つあります。
		一つは成功した場合、もう一つは失敗した場合です）。<br/>

		<code>Action</code>（あなたが作成したコントローラコンポーネント）はこれらの<em>論理的な</em>
		結果マッピング名がベースになっています。"success", "failure", "ready", "ok", "UserIsIncompetent"
		などの単語を使って<code>ActionServlet</code>に報告を返します。
		Strutsシステムは（あなたが書いた設定を通して）適切な<em>特定の</em>ページへどのようにフォワードするかを理解しています。
		この方法には、XML設定ファイルを編集するだけでビュー層の再設定ができるという利点もあります。

		この時点で、Strutsはどのようにコントローラコンポーネントへ委譲するか、
		コントローラの処理結果として何を表示するかを理解しています。
		アプリケーションの「モデル」部分は完全にあなた次第で、コントローラコンポーネント内から呼び出されます。
   </li>
<primary>
   <li>
      You may also associate a Java Bean with an action (or set of actions) in
      the Struts configuration file. The Java Bean is used as a repository for
      form or display data that can be communicated between the view and
      controller layer.<br/>

      These Beans are automatically made visible to your controller components
      (like <code>LoginAction</code>) and any view page that is associated with
      that controller. <br/>

      These Beans can also be validated with the help of the Struts system to
      help insure that the user is putting good data in the form. They can be
      carried along with a session, allowing forms to span multiple pages of
      the view, and Actions in the controller.<br/>

      <strong>Note</strong>: You must be using some sort of server-side
      technology (JSP, Velocity, XSLT) for the view layer (going <em>to</em> the
      client) to see this data (plain HTML won't work). Struts works on the
      server side, so the client's view has to be composed there.<br/>

      The client feeds the data back through normal form submission (POST/GET)
      methods, and the Struts system updates that data in the Bean before
      calling your controller components.
   </li>
</primary>
   <li>
		Struts設定ファイル内のアクション（またはアクションの集合）とJava Beanを関連づけることも出来ます。
		このJava Beanは、ビューとコントローラ層の間でやり取り可能な、
		フォームや表示データのリポジトリとして使用されます。<br/>

		これらのBeanは (<code>LoginAction</code>のような) コントローラコンポーネントや、
		コントローラに関連したビューページから自動的に見えるようになっています。<br/>

		ユーザがフォームに正しいデータを入力する手助けとなるよう、
		Strutsシステムを使ってこれらのBeanを検証することも出来ます。
		Beanと一緒にセッション情報を送れるので、ビューの複数ページ、
		コントローラの複数Actionに渡ってフォームを使うことができます。<br/>

		<strong>注</strong>: このデータを（クライアント<em>へ</em>向かう）ビュー層で見るためには、
		何らかの種類のサーバサイド技術(JSP, Velocity, XSLT)を利用しなくてはいけません
		（普通のHTMLではダメです）。
		Strutsはサーバ側で動作するため、クライアントのビューはサーバ側で作成しなければなりません。

		通常フォームが発行する(POST/GET)メソッドを通してクライアントはデータを送り返し、
		Strutsシステムはそのデータをコントローラコンポーネントを呼び出す前にBeanに書き込みます。
   </li>
<primary>
   <li>
      Within your web application will be pages that represent the view your
      users will see. These can be JSP pages, Velocity Templates,
      XSLT pages, and so forth.
      A set of JSP tags is bunded with the Struts distribution so that you
      can get started right away, but any standard presentation technology
      can be used with Struts.<br/>

      Even plain HTML files can be used within your Struts application,
      although they will not take full advantage of all of the dynamic
      features.<br/>

      Following the example of the Struts JSP taglibs, several other
      packages are available to make the framework easy to use with your
      favorite presentation technology.
      For Velocity templates, there are the
      <a href="http://jakarta.apache.org/velocity/">Velocity</a> ViewTools
      for Struts.
      If you want to use XSLT in you application, you can choose between
      <a href="http://www.openroad.ca/opencode/">stxx</a> and
      <a href="http://it.cappuccinonet.com/strutscx/">
      StrutsCX</a>.<br/>

      These packages make the standard Struts framework elements look and
      feel like a seamless part of the original presentation technology.
      Struts also makes it easy to mix and match.
      If need be, you can use JSP, Velocity templates, and XSLT all in
      the same application!<br/>

      Since Struts relies on standard Servlet technologies, you should be
      able to use any Java presentation technology with Struts.
   </li>
</primary>
   <li>
		Webアプリケーション内でユーザが見るビューに相当するのがページです。
		JSPページやVelocityテンプレート、XSLTページなどが使えます。
		JSPタグのセットはStruts配布に含まれているのですぐに使えますが、
		標準のプレゼンテーション技術ならどれでもStrutsで使えます。<br/>

		Strutsアプリケーションでは普通のHTMLファイルも使えますが、
		その場合はすべての動的機能の利点をまったく生かせません。<br/>

		StrutsのJSPタグライブラリのサンプルの他にも、
		好きなプレゼンテーション技術と組み合わせてこのフレームワークを使いやすくするパッケージがいくつもあります。
		Velocityテンプレートについては、Struts用の<a href="http://jakarta.apache.org/velocity/">Velocity</a>ビューツールがあります。
		アプリケーションでXSLTを使用したいのなら、<a href="http://www.openroad.ca/opencode/">stxx</a>か
		<a href="http://it.cappuccinonet.com/strutscx/">StrutsCX</a>のどちらかを選ぶことができます。<br/>

		これらのパッケージはStrutsフレームワークの標準要素のルックアンドフィールを、
		元のプレゼンテーション技術のシームレスな一部分のようにすることができます。
		また、Strutsは他の技術と組み合わせやすくなっています。必要であれば、
		JSPやVelocityテンプレート、XSLTを同じ一つのアプリケーションでまとめて使うことができるのです。<br/>

		Strutsは標準サーブレット技術に準拠しているので、どんなJavaプレゼンテーション技術でも組み合わせて使えるはずです。
   </li>
<primary>
   <li>
      While the focus of the Struts framework is on the controller,
      the presentation layer is a significant part of any application.
      The Struts JSP taglibs include a number of generic and Struts-specific
      tags to help you use dynamic data in your view. <br/>

      The custom JSP tags account for a good deal of the Struts code base. It
      is educational to note that as of version 1.1b3 the Java code for the
      core of Struts was about 28,000 lines, and the Java code for the tag
      libraries (including tiles) was about 41,000 lines.<br/>

      These tags help you glue your view layer to the controller layer without
      having to embed a lot of Java in the JSP. This gives the page an XML
      look, and can be easier for web designers to deal with than a plain JSP. It
      also helps minimize dependencies between the controller and view.<br/>

      The custom tags are used to create forms (and invisibly interact with the
      Bean mentioned previously), logically forward to other pages, and invoke
      other actions of the web application.<br/>

      There are also tags that help you with internationalization, error
      messages, etc.<br/>

      All of these abilities depend in some way on the configuration files you
      supplied to Struts.
   </li>
</primary>
   <li>
		Strutsフレームワークはコントローラに焦点を合わせていますが、
		プレゼンテーション層はどんなアプリケーションでも重要な役割を占めています。
		StrutsのJSPタグライブラリには、作成するビューで動的なデータが使いやすくなるように、
		汎用のタグやStruts固有のタグをたくさん盛り込んでいます。<br/>

		このカスタムJSPタグはStrutsコードベースのかなりの割合を占めています。
		ご参考までに、バージョン1.1b3時点で、StrutsコアのJavaコードが約28,000行なのに対し、
		（Tilesを含む）タグライブラリのJavaコードは約41,000行です。<br/>
		
		これらのタグは、JSPにたくさんのJavaコードを埋め込まずに、
		ビュー層とコントローラ層をくっつけるのに役立ちます。これによってページはXMLみたいになり、
		通常のJSPよりもWebデザイナが扱いやすくすることが可能です。
		また、コントローラとビューとの間の依存性を最小限にするのに役立ちます。<br/>
		
		このカスタムタグは、フォーム生成（そして上述の、見えないところでのBeanとのやり取り）、
		他のページへの論理フォワード、そしてWebアプリケーションの他のアクションの起動で使用します。<br/>

		また、国際化やエラーメッセージなどに役立つタグもあります。<br/>

		これらの機能はすべて、あなたがStrutsで用意する設定ファイルに何らかの形で依存します。
   </li>
</ul>
<primary>
<p>
   It is important for you to remember that the mechanism described here is
   only in effect when the <code>ActionServlet</code> is handling the
   request.
</p>
</primary>
<p>
	重要なこととして、ここで説明したメカニズムは <code>ActionServlet</code>
	がリクエストを扱う場合のみ有効であることを覚えておいてください。
</p>
<primary>
<p>
   Since this only happens when a request is submitted that causes your
   container (i.e. Tomcat, WebSphere, etc.) to call <code>ActionServlet</code>,
   you must be sure that any page that relies on Struts is done through a
   request that will map to the <code>ActionServlet</code> (i.e. has a
   <code>.do</code> extension).
</p>
</primary>
<p>
	このメカニズムが動作するのは、リクエスト発行によってコンテナ（例: Tomcat, WebSphereなど）
	が<code>ActionServlet</code>を呼びだす場合だけなので、
	Strutsに依存したページが<code>ActionServlet</code>にマップされたリクエスト
	(例: <code>.do</code> 拡張子を持つもの) を通して処理されているか確認しなくてはいけません。
</p>
 </section>

</chapter></body></document>
