- 追加された行はこの色です。
- 削除された行はこの色です。
- Struts関連 へ行く。
→SAStruts関連
→[[JSP関連]]
→[[Java関連]]
→JavaのWebアプリ開発
→JBoss Seam関連
→DI(依存性注入)
→Webアプリ開発
→トランザクショントークン
→Webサーバ
#contents
----
*Webサイト [#t1934283]
-http://struts.apache.org/
-http://struts.apache.org/release/2.3.x/docs/struts-2-maven-archetypes.html
**環境構築 [#n8ff53b9]
大雑把な流れは以下の通り
-JDKをインストール
-Tomcatをインストール
-Eclipseをインストール
-TomcatプラグインをEclipseに追加
--http://www.eclipsetotale.com/tomcatPlugin.html
-[[Struts環境構築>http://tech.1-east.net/201004/225.html]]
**Tomcat [#p6704e5a]
-http://tomcat.apache.org/
-[[【はじめての方向け】Apache Tomcatのインストール方法を簡単に!>https://eng-entrance.com/java-servlet-tomcat-install]] 2019.8
**ドキュメント [#td181fde]
-http://struts.apache.org/release/2.3.x/index.html
-http://struts.apache.org/release/2.3.x/docs/tutorials.html
*入門記事、リファレンス [#n810abe3]
-[[Strutsについて>https://qiita.com/adevalue/items/1b4dea67cf1c96f937c3]] 2016.9
-[[Strutsの常識を知り、EclipseとTomcatの環境構築 (1/4)>http://www.atmarkit.co.jp/ait/articles/0807/31/news129.html]]
-[[@いう間にWebアプリを作れる「Struts 2」入門>http://www.atmarkit.co.jp/fjava/special/struts2/struts2_1.html]]
--いまいち使えない記事…
-[[Webアプリの常識をJSPとStrutsで身に付ける>http://www.atmarkit.co.jp/fjava/index/index_webjousiki.html]]
-[[Apache TomcatとJakarta TaglibsとApache Strutsとその他の部屋>http://kamakura.cool.ne.jp/oppama/ssja/index.html]]
-[[Strutsを使うWebアプリケーション構築術>http://www.atmarkit.co.jp/fjava/index/index_struts.html]]
-[[忘れっぽいエンジニアのための jakarta Strutsリファレンス>http://struts.wasureppoi.com/]]
-[[Struts>http://www.ne.jp/asahi/hishidama/home/tech/struts/index.html]]
-[[ケーピーの技術ノート Struts関連>http://kpnote.cocolog-nifty.com/blog/2008/11/struts-5710.html]]
-[[struts「設計パターン」についてまとめてみる>http://ledsun.hatenablog.com/entry/20120202/1328200624]] 2012.2.2
*Tips [#ec437f51]
-[[LookupDispatchActionクラス>http://www.javaroad.jp/opensource/js_struts14.htm]]
--1フォームに複数のsubmitボタンがあり、どれを押すかによって違う動きをさせたいときに使う。
-[[ForwardActionクラス>http://www.javaroad.jp/opensource/js_struts13.htm]]
--単純に画面遷移だけを行いたいときに使うActionクラス
-[[DynaActionForm>http://www.atmarkit.co.jp/fjava/rensai3/struts04/struts04_2.html]]
--フォームの項目をstruts-config.xmlに設定して自動生成できる
--<form-property>タグで指定した内容に合わせてformクラスを生成してくれる
--但し使用できるプロパティの型に制限がある。
--値取得の例
DynaActionForm dForm = (DynaActionForm)form;
int n = ((Integer)dForm.get("xxx")).intValue();
-[[エラーメッセージにヘッダーとフッターをつける>http://struts.wasureppoi.com/taglib/04_headder.html]]
--エラーメッセージのプロパティファイルに以下の値を作成する
--errors.header : エラーメッセージ出力前に1回出力される。
--errors.footer : エラーメッセージが全て出力後に1回出力される。
--errors.prefix : 各エラーメッセージの最初に出力される
--errors.suffix : 各エラーメッセージの最後に出力される
-[[validate()メソッドによる入力値検証>http://www.stackasterisk.jp/tech/java/strutsSec02_01.jsp]]
-http://strutstestcase.sourceforge.net/
-[[StrutsTestCase>http://634.ayumu-baby.com/strutstestcase/index.html]]
--Actionクラスの単体テストをするためのフレームワーク
--Actionによる画面遷移と定義されたActionErrorのチェックを行うことができ
--JUnitと組み合わせて動作するように設計されている
--Struts1.3.5から単体テスト機能がStrutsに追加されたのでそれを使うならStrutsTestCaseは不要
-リクエストヘッダの参照
HttpServletRequest req = RequestUtil.getRequest();
Enumeration<String> e = req.getHeaderNames();
while( e.hasMoreElements() ) {
String s = e.nextElement();
System.out.println(s + "=" +req.getHeader(s) );
}
-セッション情報のバインドとアンバインドのタイミングで何かするには
--HttpSessionBindingListener を実装すればよい
-セッションのロケールを変更する
HttpServletRequest req = RequestUtil.getRequest();
HttpSession session = req.getSession();
session.setAttribute(Globals.LOCALE_KEY, Locale.ENGLISH);
-[[メッセージリソースファイルの日本語処理>http://www.javaroad.jp/opensource/js_struts16.htm]]
-[[Struts でフォームに配列を使う>http://www.res-system.com/weblog/item/242]]
-[[配列のデータを取得したい。>http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=9471&forum=12&1]]
-[[StrutsでHTMLの表示や入力に配列を使用したい>http://www.whitemark.co.jp/tec/struts/strutsarray.html]]
-[[バリデータの自作>http://kamakura.cool.ne.jp/oppama/ssja/index.html]]
-[[Strutsでテキストをダウンロードする>http://kamakura.cool.ne.jp/oppama/ssja/struts-download.html]]
-[[Strutsでのプルダウンの作り方>http://www.masatom.in/pukiwiki/Struts/%A5%D7%A5%EB%A5%C0%A5%A6%A5%F3%A4%CE%BA%EE%A4%EA%CA%FD/]]
-[[URLの取得>http://www.memorycraft.jp/2009/02/sastrutsurl.html]]
@Resource
protected Map requestScope;
@Execute(validator = false)
public String test(){
String requestUri = (String)requestScope.get("javax.servlet.forward.request_uri");
String contextPath =(String)requestScope.get("javax.servlet.forward.context_path");
String servletPath =(String)requestScope.get("javax.servlet.forward.servlet_path");
String pathInfo =(String)requestScope.get("javax.servlet.forward.path_info");
String queryString =(String)requestScope.get("javax.servlet.forward.query_string");
System.out.println(requestUri);
System.out.println(contextPath);
System.out.println(servletPath);
System.out.println(pathInfo);
System.out.println(queryString);
return "test.html";
}
--もしくは request.getURI()
--関連:[[サーブレットパスの構成要素を取得する>http://www.atmarkit.co.jp/fjava/javatips/067jspservlet030.html]]
getContextPath コンテキストパス
getServletPath サーブレットパス
getPathInfo 拡張パス
getPathTranslated 拡張パス(物理パス)
getRequestURL リクエスト時のURL
getRequestURI コンテキストパスから拡張パスまで
-[[サーブレット仕様の認証を使わずにgetRemoteUserやisUserInRoleを使う>http://d.hatena.ne.jp/paulownia/20080918/1221751667]]
--独自の認証機構を使うと自由にログイン処理を記述できる代わりにHttpServletRequestのgetRemoteUserやisUserInRoleは使えない。
--しかし独自の認証でもHttpServletRequestWrapperとFilterを組み合わせれば、getRemoteUserやisUserInRoleを有効にできる。
-[[画面遷移とアクセス制御の方法>http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=8447&forum=12&3]]
-[[「どのスコープにもBean org.apache.struts.taglib.html.BEAN がありません」というエラー>http://maebashi.cool.ne.jp/kuruchi/memo1.shtml]]
--どっかタグが抜けてたり閉じ忘れてたり。
--formでないのにproperty設定してるタグを使っている。formのネスト内のみ有効のタグは、html:textareaやhtml:textやhtml:passwordなど
*struts-config.xmlのタグ [#fc59d962]
-<global-exceptions> 例外処理の設定
--[[例外発生時のカスタムエラーページの設定>http://charie99.egloos.com/page/6]]
--やり方はいろいろあるが、struts-config内におけるエラーハンドリングの記述がま
ず考えられる手段だといえるだろう。
<global-exceptions>
<exception key="error.global" type="java.lang.Exception" path="/error.html"/>
</global-exceptions>
(struts-config.xml)
-<global-forwards> 共通の遷移
-<action-mappings> Actitonクラスと画面遷移(forward)の設定
--forwardはmapping.findforward()の引数に渡す文字列
-<message-resources> メッセージリソース
--(ベース名).properties 日本語を使うときはnative2asciiを使う
-<plug-in> プラグインの設定
-<form-beans> フォームクラスの設定
-<data-sources> データソースの設定