如果你真的想用斜线分隔你的动作,你应该使用NAMESPACE
,试试这个:
<package name="profile" extends="struts-default" namespace="/Profile">
<action name="*" method="{1}" class="com.controller.Profile">
<result name="view" tiles="viewProfile">viewProfile</result>
<result name="edit" tiles="editProfile">editProfile</result>
</action>
</package>
如果您尝试在 url 上使用参数,则应考虑使用
<constant name="struts.enable.SlashesInActionNames" value="true"/>
在您的 Struts 2 配置文件中。
关于Wildcart Mapping文档,您也可以这样做:
<action name="**" method="{1}" class="com.controller.Profile">
<result name="view" tiles="viewProfile">viewProfile</result>
<result name="edit" tiles="editProfile">editProfile</result>
</action>
** matches zero or more characters including the slash ('/') character.
您还可以在 Wildcart Mapping文档中找到它。
您应该首先考虑您真正想要什么,然后进行配置和实现。
在你的情况下,Struts 2 认为你的动作有斜线,关于动作配置
带有斜杠
的动作名称 如果您的动作名称中包含斜杠(例如, <action name="admin/home" class="tutorial.Admin"/>
),您需要通过 struts.xml 文件中的常量指定 ,特别允许在动作名称中使用斜杠
<constant> name="struts.enable.SlashesInActionNames" value="true"/>
。
请参阅 JIRA 问题 WW-1383 进行讨论,因为将此属性设置为 true 会产生副作用。
带有点和破折号的动作名称 尽管动作命名非常灵活,但在使用点(例如)和/或破折号(例如)
时应该注意。虽然点表示法目前没有已知的副作用,但破折号表示法会导致为某些标签和主题生成的 JavaScript 出现问题。请谨慎使用,并始终尝试使用驼峰式操作名称(例如。
)或下划线(例如。)。create.user
my-action
createUser
my_action
所以 Struts 2 会将你的斜杠转换为下划线。