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中存在多个逻辑处理方法,且不同的处理逻辑可能需要不同的校验规则,在这种情况下,就需要通 ...
随机推荐
- AIX系统的备份和恢复
1.AIX备份命令
- [易学易懂系列|rustlang语言|零基础|快速入门|(3)|所有权Ownership]
今天我们来讲讲rust最难,也是最重要的概念: Ownership,Borrowing,Lifetimes 首先我们来看看:ownership(所有权) 我们来看看下面的代码: let a = [1, ...
- python 多线程、线程锁、事件
1. 多线程的基本使用 import threading import time def run(num): print('Num: %s'% num) time.sleep(3) if num == ...
- Spring MVC使用AOP实现审计日志
先定一个注解,用于在Controller方法上记录每个方法的用途. package com.zjf.spring.annotation; import java.lang.annotation.Doc ...
- web性能优化--服务器端(二)
静态资源用CDN部署 添加Expires或者cache-control报文头 Gzip压缩传输文件 配置Etags 使用Get ajax请求 避免空图片src 尽早flush response 减少c ...
- ESP8266内置的定时器库--Ticker库
Ticker的功能非常简单,就是规定时间后调用函数 总体上,根据功能可以把方法分为两大类: 定时器管理方法: 定时器启用方法: detach() 停止定时器 active() 定时器是否 ...
- 对js数组去重的研究
1.利用es5 let arr = [1, 2, 3, 4, 5, 6, 7, 1, 2, 3] const unique=arr=>{ return Array.from(new Set(ar ...
- MTBF测试
本文转载自:https://blog.csdn.net/liuhaoemail/article/details/50531489 MTBF测试 目前,终端侧的可靠性测试基本上是采用称为”MTBF测试” ...
- OverFeat:基于卷积网络的集成识别、定位与检测
摘要:我们提出了一个使用卷积网络进行分类.定位和检测的集成框架.我们展示了如何在ConvNet中有效地实现多尺度和滑动窗口方法.我们还介绍了一种新的深度学习方法,通过学习预测对象边界来定位.然后通过边 ...
- TCP大文件上传与UDP协议
一.UCP大文件上传(解决粘包问题) ①客户端 import socket, os, json, struct client = socket.socket() client.connect(('12 ...