目次

SAStruts/Action/URLとのマッピング

基本

公式のドキュメントによると・・・ Super Agile Struts - Feature Reference

ということのようだ。

http://a.b.co.jp/hoge/piyo/

というものだと・・・HogeActionpiyo メソッドを実行することになる。

Action をさらにパッケージ分割などするとおかしいことになるとおうが、 それはそれで優先順位があるツリー構造で名前がバッティングしないようにつければスラッシュでディレクトリを潜るように指定することでちゃんと呼び出せるようになっている。

つまりパッケージ名、Action名、メソッド名が階層を超えて重複させんなよ。

メソッド解決の優先順位

パラメータを自由に取れるようになると、当然そのパラメータ次第ではメソッド名とかぶってしまう状況も出てくる。 このような場合SAStrutsでは明示的に付けられているメソッド名を優先しパターンのほうは最後に使って解決するようである。

逆に言うと、パターンが取りうるパラメータは既存のメソッドと被らないように考慮する必要があるということだ。

Apacheとの連携を考慮したURL

開発中は

http://localhost:8080/hoge/

みたいなURLがアプリのルートになっていると思う。

これを、ROOT.war で書き出してドメインのルートと一致させるのが正攻法。 この場合

${ f:url("hogehoge") }

のような記述もちゃんと追従する。

http://localhost/hoge/

でアクセスして

ajp://localhost:8009/piyo/

に繋ぐようなやつはSAStruts側でhogeを検出できないので

${ f:url("hogehoge") }

の記述がおもいっきりズレる

同様に

http://localhost/

でアクセして

ajp://localhost:8009/piyo/

に繋ぐようなやつも階層がズレてちゃんと繋がらない。

挙動チェック

jp.co.hogehoge.action.IndexActionのindexメソッドへのアクセス

http://localhost:8080/aaaa/
http://localhost:8080/aaaa/index/

return “index.jsp”の場合の参照されるindex.jsp

view/index.jsp

return “/index.jsp”の場合の参照されるindex.jsp

view/index.jsp

jp.co.hogehoge.action.IndexActionのpiyoメソッドへのアクセス

http://localhost:8080/aaaa/piyo

return “index.jsp”の場合の参照されるindex.jsp

view/index.jsp

※view/piyo/index.jspが存在しても↑が参照される。

return “/index.jsp”の場合の参照されるindex.jsp

view/index.jsp

jp.co.hogehoge.action.HogeActionのindexメソッドへのアクセス

http://localhost:8080/aaaa/hoge/
http://localhost:8080/aaaa/hoge/index

return “index.jsp”の場合の参照されるindex.jsp

view/hoge/index.jsp

return “/index.jsp”の場合の参照されるindex.jsp

view/index.jsp

return “../index.jsp”の場合の参照されるindex.jsp

view/index.jsp

return “../piyo/index.jsp”の場合の参照されるindex.jsp

view/piyo/index.jsp

jp.co.hogehoge.action.PiyoActionのindexメソッドへのアクセス

http://localhost:8080/aaaa/piyo/
http://localhost:8080/aaaa/piyo/index

※IndexActionのpiyoメソッドとアクセスするURLが被っている

アクセスされるAction

PiyoAction

jp.co.hogehoge.action.fuga.IndexActionのindexメソッドへのアクセス

http://localhost:8080/aaaa/fuga/
http://localhost:8080/aaaa/fuga/index

return “index.jsp”の場合の参照されるindex.jsp

view/fuga/index.jsp

jp.co.hogehoge.action.IndexActionのfugaメソッドへのアクセス

http://localhost:8080/aaaa/fuga/
http://localhost:8080/aaaa/fuga/index

※FugaActionのindexメソッドとアクセスするURLが被っている アクセスされるAction IndexActionのfugaメソッドにアクセスされる。

jp.co.hogehoge.action.fuga.FugafugaActionのindexメソッドへのアクセス

http://localhost:8080/aaaa/fuga/fugafuga/
http://localhost:8080/aaaa/fuga/fugafuga/index

return “index.jsp”の場合の参照されるindex.jsp

view/fuga/fugafuga/index.jsp

挙動チェックからわかった動き

タグ