struts2.5.14.1版本中action匹配问题

问题描述:
在使用action通配符时,不能调转到相应的网页或action
出现:There is no Action mapped for namespace [/] and action name [loginUserAction] associated with context path [/structs2].

这里写图片描述

解决方法:

以下描述都在struts2.5.14.1版本下。

方法1:直接在package添加

<global-allowed-methods>login</global-allowed-methods>

方法2:修改struts.enable.DynamicMethodInvocation,在action下添加
struts.enable.DynamicMethodInvocation 默认是为 false。

<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

<allowed-methods>login</allowed-methods>

例:struts.xml配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
    <!-- 动态调用 -->
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <package name="test" namespace="/" extends="struts-default">
        <!-- <global-allowed-methods>login</global-allowed-methods> -->
        <action name="helloAction" class="com.ldsh.web.action.TestAction" method="hello">
            <result name="success" type="redirect">hello.jsp</result>
        </action>
        <action name="*UserAction" class="com.ldsh.web.action.UserAction" method="{1}">
            <result name="success" type="redirect">result.jsp</result>
            <allowed-methods>login</allowed-methods>
        </action>
    </package>
</struts>

注:
1、execute,input,back,cancel,browse,save,delete,list,index这些方法不需配置,即可使用
2、匹配多个和所有

<!-- 匹配多个 -->
<global-allowed-methods>[方法名1][,方法名n]</global-allowed-methods>
<allowed-methods>[方法名1][,方法名n]</allowed-methods>
<!-- 匹配所有 -->
<global-allowed-methods>regex:.*</global-allowed-methods>
<allowed-methods>regex:.*</allowed-methods>

3、struts2的一下默认配置参考
st_struts2-core-2.5.14.1.jar下
变量配置:/org/apache/struts2/default.properties
struts.xml配置:/struts-default.xml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值