使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便:
<action name="Crud_*" class="example.Crud" method="{1}">

最近更新struts版本到2.5.8时,发现无论怎么访问都无法启用通配符调用,一直在报如下错误:

There is no Action mapped for namespace [/] and action name [Crud_*] associated with context path [].
 
在struts2.5中使用了SMI(Strict Method Invocation)严格方法调用.它继承自DMI(Dynamic Method Invocation);
关于DMI简单了解就是struts2定义的一种方法调用方式,实际工作中常用的方法调用方式是struts1中的通配符方式.因为很少用(我自己也没用过),并且不安全,官方文档写的又看不太懂,这里就不介绍了.
官方介绍:DMI可以理解为"border police"边境政策,SMI是"tax police"税收政策;也就是SMI更严格.
SMI是在struts-default包上定义,默认值为true,同时没有全局关闭的方式.可以在你每个定义的包上单独关闭.
关闭包SMI方式:
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<package name="default" extends="struts-default" strict-method-invocation="false"></package>
 
SMI造成所有的访问,其实都是经过拦截处理的.允许方法访问可以通过以下方式:
 
解决方式:
    1 如果你的引用包struts2-core是2.5版本需要更新struts.xml的文件头:    
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">

2 并在struts.xml中开放方法访问:
  方式一:全局配置

    <package name="default" extends="struts-default">
      <global-allowed-methods>regex:.*</global-allowed-methods>
    </package>

        方式二:action标签内配置(多个方法逗号隔开)    

    <action name="login" method="login" class="loginAction">
      <result name="login">/WEB-INF/login.jsp</result>
      <allowed-methods>login</allowed-methods>
    </action>

局限于技术和英语水平,建议结合官方文档看本博客.

 参考资料:

  官方文档 https://struts.apache.org/core-developers/action-configuration.html#wildcard-method

struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []的更多相关文章

  1. struts2中错误There is no Action mapped for namespace [/] and action name [] associated with context path

    1 There is no Action mapped for namespace [/] and action name [] associated with context path [/Stru ...

  2. eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi

    下午在eclipse中配置struts2时报: There is no Action mapped for namespace [/] and action name [Login] associat ...

  3. Struts2中关于"There is no Action mapped for namespace / and action name"的总结

    今天在调试一个基础的Struts2框架小程序.总是提示"There is no Action mapped for namespace / and action name"的错误. ...

  4. struts2报错:There is no Action mapped for namespace [/] and action name [userAction!add]

    使用struts2.3进行动态方法调用时出现: There is no Action mapped for namespace [/user] and action name [user!add] a ...

  5. Struts2.5以上版本There is no Action mapped for namespace [/] and action name [userAction_login] associated with context path []

    分析:Struts2在2.5版本后添加strict-method-invocation(严格方法访问),默认为true,不能使用动态方法调用功能,故需设为false struts.xml设置如下: & ...

  6. struts2中错误提示:There is no Action mapped for namespace / and action name

    当在struts2中运行时出现如上所述错误时: 1.在src目录下创建struts.xml一定要注意拼写 2.struts.xml文件中引入和extend是否正确 3.在web.xml 中<we ...

  7. Struts2中There is no Action mapped for namespace错误解决方法

    1.我的原有配置 jsp表单提交路径 <form class="layui-form" id="form" action="${ctx }/me ...

  8. Struts2中DMI(动态方法调用)的错误问题(There is no Action mapped for namespace [/xxx] and action name [xxx!yyy] a)

    默认的Struts.xml中是这样的 <constant name="struts.enable.DynamicMethodInvocation" value="f ...

  9. struts2常见配置解决错误There is no mapped for namespace[/] and action name

    我碰到这个错误的原因是我把配置文件名写成了Struts.xml,改成struts.xml就可以了. 在确定struts.xml本身并没有写错的情况下,那么发生错误有可能是路径,配置文件名. 如果实在找 ...

随机推荐

  1. JS使用MD5加密

    MD5加密JS代码 /* * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algor ...

  2. Java 18套JAVA企业级大型项目实战分布式架构高并发高可用微服务电商项目实战架构

    Java 开发环境:idea https://www.jianshu.com/p/7a824fea1ce7 从无到有构建大型电商微服务架构三个阶段SpringBoot+SpringCloud+Solr ...

  3. g++ 生成C++ .so库文件,并调用示例

    Tags: g++ C++ so library   在Linux系统下用g++命令编译C++程序.也可以生成so,a链接库   示例一 编译时链接so库 Test.h 文件内容   Main.cpp ...

  4. js实现千位分隔符

    var s=123456789; var seperate=s.toString().replace(/\B(?=(\d{3})+$)/g,',');

  5. iframe内嵌页面——跨域通讯

      <template> <div class="act-form"> <iframe :src="src" ref=" ...

  6. ORACLE 存储过程提高

    1.SQLCODE和SQLERRM 2.%TYPE和%ROWTYPE的使用 3.sql%rowcount的作用 1.SQLCODE和SQLERRM SQLCode:数据库操作的返回码,其中 --成功: ...

  7. sql sever 查询用户所有的表和各个表数据量

    和oracle有区别, 需要关联表 SELECT A.NAME ,B.ROWS  FROM sysobjects  A JOIN sysindexes B ON A.id = B.id WHERE A ...

  8. Oracle创建上下文 SYS_CONTEXT

    Oracle创建上下文 SYS_CONTEXT 1. 系统默认的一些参数 set heading offselect SYS_CONTEXT('USERENV', 'TERMINAL') termin ...

  9. 特殊权限 - SUID GUID STICKYBIT

    ◆ SUID ( Set User ID ) Linux里,用户的ID被称作UID.在实际生产中,可能需要临时借用别的用户执行程序,因此需要能够临时变更自己UID的机能叫做SUID.借助SUID权限, ...

  10. idou老师教你学Istio 22 : 如何用istio实现调用链跟踪

    大家都知道istio可以帮助我们实现灰度发布.流量监控.流量治理等一些功能. 每一个功能都帮助我们在不同场景中实现不同的业务.那么其中比如流量监控这种复杂的功能Istio是如何让我们在不同的应用中实现 ...