struts2 2.5.16 通配符方式调用action中的方法报404
1、问题描述
在struts.xml中配置用通配符方式调用action中的add()方法,访问 http://localhost:8080/Struts2Demo/helloworld_add.action时,出现了这个熟悉的错误:
HTTP Status 404 – Not Found
Type Status Report
Message There is no Action mapped for namespace [/] and action name [helloworld_add] associated with context path [/Struts2Demo].
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.35
2、相关代码
struts.xml中部分相关代码
<package name="default" namespace="/" extends="struts-default">
<action name="helloworld_*" method="{1}" class="com.icheny.action.HelloWorldAction">
<result>/result.jsp</result>
<result name="add">/{1}.jsp</result>
<result name="update">/{1}.jsp</result>
</action>
</package>
HelloWorldAction.java中部分相关代码
public String add()
{
return "add";
} public String update()
{
return "update";
}
3、原因
由于struts2 2.5版本的安全度提高了一个台阶,通配符禁止使用,所有不安全的访问都必须要在struts.xml中声明允许。我用的是2.5.16版本的struts,因此出现了这个错误。
4、解决方案
在package中添加属性:strict-method-invocation="false"
修改之后的struts.xml中的package部分代码为:
<package name="default" namespace="/" extends="struts-default" strict-method-invocation="false">
<action name="helloworld_*" method="{1}" class="com.icheny.action.HelloWorldAction">
<result>/result.jsp</result>
<result name="add">/{1}.jsp</result>
<result name="update">/{1}.jsp</result>
</action>
</package>
再次访问http://localhost:8080/Struts2Demo/helloworld_add.action,正常跳转:

struts2 2.5.16 通配符方式调用action中的方法报404的更多相关文章
- struts2 利用通配符方式解决action太多的问题
<!-- 创建包default,继承struts-default --> <package name="default" extends="str ...
- Action中动态方法的调用 Action中通配符的使用 Result的配置
Action中动态方法的调用 动态方法调用(Dynamic Method Invocation,DMI) 标识符:! 一.通过以下选中的文件来查看是否禁止调用动态方法
- Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)
1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...
- Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。
1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...
- mybatis-plus调用自身的 selectById 方法报错:org.apache.ibatis.binding.BindingException:
mybatis-plus的版本号是 2.0.1,在调用自身的insert(T)的时候没有报错,但是执行update报错,调用selectById.deleteById的时候也报错.也就是涉及到需要主键 ...
- 在action中进行文件下载,下载时运行不报错,可是也不下载
在写前端下载页面时,使用ajax方式调用action中的方法,然后就将下载内容返回js中了,所以没有下载,之后改为使用Windows.location进行下载,就没有问题了. action中代码: i ...
- struts2的占位符*在action中的配置方法
转自:https://blog.csdn.net/u012546338/article/details/68946633 在配置<action> 时,可以在 name,class,meth ...
- Struts2(五.用户注册的实现及整合Action的配置方法)
一.用户注册功能 register.jsp页面 若是jquery ajax方式提交给action,还要回到jquery,控制权在jquery若是表单方式提交给action,控制权交给action &l ...
- struts2:数据校验,通过Action中的validate()方法实现校验(续:多业务方法时的不同验证处理)
前文:struts2:数据校验,通过Action中的validate()方法实现校验,图解 如果定义的Action中存在多个逻辑处理方法,且不同的处理逻辑可能需要不同的校验规则,在这种情况下,就需要通 ...
随机推荐
- 脚本_通过进程与端口判断myslq服务
#!bin/bashif [[ $port -eq 1 || $porcess -eq 2 ]];then #通过条件判断端口和进程执行的返回值. echo "mysql is s ...
- Centos 7.5 双网卡内外网同时访问路由设置
说明:服务器有两张网卡分别是eth0.eth1,eth0配置内网IP:192.168.1.1/24,eth1配置外网IP:10.1.1.1/24:要求192.168.0.0/16网段走网卡eth0,网 ...
- 安装kibana可视化平台工具
1.安装kibana 命令: wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-linux-x86_64.tar.gz ...
- linux如何判断上一条命令执行是否正确
echo $? 如果输出0代表结果正确 如果输出非0代表结果错误
- 用jquery控制表单提交
可以监听表单submit提交事件给form一个id 吧button的type为submit $(form的id).submit(function(){ if(window.confirm('你确定要取 ...
- 别再误解MySQL和「幻读」了
The so-called phantom problem occurs within a transaction when the same query produces different set ...
- 有关pip报错的问题
错误消息:“Fatal error in launcher: Unable to create process using '"' 解决办法: python3解决方案:python3 -m ...
- 基于Ubuntu 搭建 WordPress 个人博客 - 开发者实验室 - 腾讯云
1.准备 LAMP 环境 安装 Apache2 在终端输入该命令 ,使用 apt-get 安装 Apache2: sudo apt-get install apache2 -y 安装好后,您可以通过访 ...
- leaflet 地图容器大小改变时,地图自适应新容器
window.onload = function () { changeDivHeight(); } //当浏览器窗口大小改变时,设置显示内容的高度 window.onresize = functio ...
- CSS设置背景色
最好用background-color:rgba(37,77,113,1); 因为用opacity会让所有自标签都改变