struts2.5.2版本使用action通配符提示找不到action的问题

struts.xml配置部分:

    <action name="*Person" class="org.apache.struts.wildcardmethod.action.PersonAction" method="{1}">
        <result name="success">/view.jsp</result>
        <result name="input">/input.jsp</result>
        <allowed-methods>create,edit</allowed-methods>
    </action>

页面请求部分:

<s:if test="personList.size > 0">
    <ol>
        <s:iterator value="personList">
            <li>
                <s:property value="firstName"/>
                <s:property value="lastName"/>

                <s:url action="editPerson" var="editUrl">
                    <s:param name="id" value="id"/>
                </s:url>
                <s:url action="deletePerson" var="deleteUrl">
                    <s:param name="id" value="id"/>
                </s:url>

                <a href="<s:property value='#editUrl'/>">Edit</a>
                <a href="<s:property value='#deleteUrl'/>">Delete</a>
            </li>
        </s:iterator>
    </ol>
</s:if>

<s:url action="createPerson" var="newUrl">
    <s:param name="id" value="0"/>
</s:url>

<p><a href="<s:property value='#newUrl'/>">Create new person.</a></p>

调用delete方法是可以,其他的都不行,报错(部分信息):

Struts Problem Report

Struts has detected an unhandled exception:

Messages:   
There is no Action mapped for namespace [/] and action name [saveOrUpdatePerson] associated with context path [/wildcard-method-selection].

找了好久都没发现什么问题,google一下,有人说是版本问题,试了一下,果然行。

在struts2.3之前的版本,正常的配置就可以了,但在struts2.3版本之后,使用通配符调用方法时,内部会验证是否允许访问该方法,所以要加上<allowed-methods>方法名1,方法名2…</allowed-methods>代码。

原文链接:http://www.cnblogs.com/gsy52300/archive/2016/08/17/5778754.html

但是为什么没有配置allowed-methods也能调用delete方法呢?execute方法能调用,这个可以理解,因为是框架里面有的,allowed-methods应该没有限制对execute方法的调用。而delete方法是自定义的(反正在ActionSupport里面没有定义),怎么就能调用呢?有待答案。

官方文档有正解! http://struts.apache.org/docs/action-configuration.html#ActionConfiguration-StrictDMI

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值