私は Struts2 を初めて使用しますが、これまで API を使用してかなりの進歩を遂げてきました。しかし、私は抜け出す必要がある何かに行き詰まっています。Spring 統合で Struts2 を使用しています。アノテーションが大好きな皆さんと同じように、アノテーション付きのアクション クラスを作成しています。
私の要件は、URL が次の性質を持つことです。
http://<DOMAIN>/program/program1.jspx
http://<DOMAIN>/program/program2.jspx
http://<DOMAIN>/program/program3.jspx
ご覧のとおり、URL には特定のパターンがあり、program1、program2、および program3 が変化し、残りはすべて静的です。他のプロジェクトのように、Spring MVC で同様の状況を非常に簡単に処理しました (現在のプロジェクトに Spring MVC を使用するオプションはありません) "/program/{program_name}.jspx"
。
しかし、struts2 で同じものを使用すると、エラーが発生します。私のアクションクラスは次のとおりです。
@Result(name="program", location="program", type="tiles")
public class ProgramAction extends ActionSupport {
@Action("program/{programName}")
public String getProgramPage() {
// few more lines of code
return "program";
}
}
エラーは
2013-02-28 15:46:35.591 WARN [http-bio-8080-exec-3] CommonsLogger.java:60
Could not find action or result
com.opensymphony.xwork2.config.ConfigurationException: There is no Action mapped for namespace / and action name program1.
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189) ~[xwork-core-2.2.1.jar:2.2.1]
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61) ~[struts2-core-2.2.1.jar:2.2.1]
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39) ~[struts2-core-2.2.1.jar:2.2.1]
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) ~[xwork-core-2.2.1.jar:2.2.1]
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475) ~[struts2-core-2.2.1.jar:2.2.1]
....
....
私のstruts.xml
ファイルは次のとおりです。
<struts>
<constant name="struts.convention.default.parent.package" value="default"/>
<constant name="struts.action.extension" value="jspx" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<package name="default" extends="struts-default, json-default, rest-default" namespace="/">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
</package>
</struts>