struts.xml の struts.package 要素

struts2.3.28

struts.package とは

要素 actions, results, reult types, interceptors, interceptor-stacks

を一論理グループにまとめる要素

「拡張ができて、サブパッケージで個々のパーツをオーバーライドができるオブジェクト」

と思えば良い

Packages are a way to group actions, results, result types, interceptors, and interceptor-stacks into a logical configuration unit.
Conceptually, packages are similiar to objects
in that they can be extended and have individual parts
that can be overridden by "sub" packages.

抜粋元

package の属性と必須/任意

抜粋元は同上

要素 必須/任意 概要
name yes 他パッケージが参照するときのキー名
extends no 他 package を継承する時、その package 名を割当てる
namespace no 名前空間(A)
abstract no 抽象パッケージの指定(未精査:いつ使う?)

(A)

URI ルーティングの意味合いでは

localhost:8080/namespace/strutsAction

namespace に該当する

  1. namespace を指定しない場合はブランクであり、"/" にならない(動作確認より)

  2. namespace="" を指定すると "/" と同値になる

【整理中】

  1. について

url-pattern 要素 を /* に指定している場合

strutsAction に対して namespace に期待外の文字列が入り得る(動作確認より)

ので Y. 明示的に "" の指定が必要と考えられる

例えば

localhost:8080/./strutsAction

localhost:8080/$/strutsAction

は 503 レスポンスを返さず strutsAction を実行する

(action 要素記載時に詳細記載予定)

<struts>
  <package name="uniqueNameYouNamed" namespace="/routingPath" extends="struts-default">
  </package>

参考元:

https://struts.apache.org/docs/package-configuration.html