开发者

How to configure one package under plain Struts2 and another under Struts2 + Rest Plugin?

I have an existing application using Struts2 for a section of the app served under "/portals/.../A" and "/portals/.../B". The configuration file looks something like this:

<struts>
   <package name="portals/*" extends="struts-default">
       <action name="A" ...> ...</action>
       <action name="B" ...> ...</action>
   </package>
</struts>

That works fine until I add the Rest Plugin jars. It seems to take over and ignore the settings.

Ideally, what I want is to keep portals untouched and add a new package called "rest" that would be handled by the Rest Plugin.

http://localhost/portals/* .... plain struts2

http://localhost/rest/* ... struts2 + rest plugin

The question is "How?".

I added some rest-plugin settings like:

<constant name="struts.convention.action.suffix" value="Controller"/>
<constant 开发者_开发技巧name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>

but the old actions are still broken.


I have not see someone place an asterix in a package name. Your package as such might actually be "portals/*"

meaning

"/portals/*/" would need to precede a call to an action within.

IE: ".../portals/*/A.action" would call action A. Anyways it is much clearer for all involved if you just call say:

<package name="portals" extends="struts-default" namespace="/">
  ...
</package>

You can have wild cards in actions. What this does is captures parts of the url letting you dynamically call methods/classes and set parameters matching that wild card for details see: http://struts.apache.org/2.1.8.1/docs/wildcard-mappings.html however as far as I know this can not be applied to packages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜