Strutsインストールメモ †
◆Strutsのインストール
・struts-1.2.7.tar.gzをダウンロード、展開して、lib以下のファイルを各ディレクトリに配置する。
ファイル | 配置先ディレクトリ |
*.jar | /WEB-INF/lib |
*.tld | /WEB-INF |
validator-rules.xml | /WEB-INF |
◆Tomcatの設定ファイル(web.xml)にStruts用のアクションマッピングを設定
・以下の記述によって *.do というリクエストは全て Struts(ActionServletクラス)に投げられるようになる。
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
・
中略
・
<servlet>
<font color=red><b><servlet-name>action</servlet-name></b></font>
<font color=red><b><servlet-class>org.apache.struts.action.ActionServlet</servlet-class></b></font>
</servlet>
<servlet-mapping>
<font color=red><b><servlet-name>action</servlet-name></b></font>
<font color=red><b><url-pattern>*.do</url-pattern></b></font>
</servlet-mapping>
</web-app>
◆Struts用タグライブラリを利用する為の設定 ・/WEB-INF以下に配置したタグライブラリを利用する為に、/WEB-INF/web.xml を編集する。 |
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
・
中略
・
<font color=red><b>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</b></font>
</web-app>
|
・ここでタグライブラリのPathに別名をつけておく。
・タグライブラリを利用するには各jspファイルのヘッダ部で、
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
のように利用するタグの宣言が必要だが、
左記のように宣言しておく事で、
<%@ taglib prefix="html" uri="/tags/struts-html" %>
と書けるようになる。
※tldファイルで宣言しているURIはそのまま使用できる?
|