struts2.5框架使用通配符无效问题

时间:2023-03-10 07:07:19
struts2.5框架使用通配符无效问题

错误:

Struts has detected an unhandled exception: 

Messages: There is no Action mapped for namespace [/person] and action name [update] associated with context path [/struts2_04]. 

  解决方法:

    不知道从哪个版本开始,action中添加了 allowed-methods 标签,所以要想让对应Action类中的方法能进行匹配,还需要在 allowed-methods 标签注册该方法才行,比如Action中有 saveUser 和 updateUser 方法,配置如下:

		<action name="*" class="com.shawn.action.UserAction" method="{1}User">
<result name="success">/{1}User.jsp</result>
<allowed-methods>saveUser,updateUser</allowed-methods>
</action>

  

总结:struts 2.5 使用通配符调用方法时,内部会验证是否允许访问该方法,所以要加上

<allowed-methods>方法名1,方法名2…</allowed-methods>代码。