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的更多相关文章

  1. struts2 利用通配符方式解决action太多的问题

    <!-- 创建包default,继承struts-default -->    <package name="default" extends="str ...

  2. Action中动态方法的调用 Action中通配符的使用 Result的配置

       Action中动态方法的调用 动态方法调用(Dynamic Method Invocation,DMI) 标识符:! 一.通过以下选中的文件来查看是否禁止调用动态方法

  3. Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)

    1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...

  4. Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。

    1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...

  5. mybatis-plus调用自身的 selectById 方法报错:org.apache.ibatis.binding.BindingException:

    mybatis-plus的版本号是 2.0.1,在调用自身的insert(T)的时候没有报错,但是执行update报错,调用selectById.deleteById的时候也报错.也就是涉及到需要主键 ...

  6. 在action中进行文件下载,下载时运行不报错,可是也不下载

    在写前端下载页面时,使用ajax方式调用action中的方法,然后就将下载内容返回js中了,所以没有下载,之后改为使用Windows.location进行下载,就没有问题了. action中代码: i ...

  7. struts2的占位符*在action中的配置方法

    转自:https://blog.csdn.net/u012546338/article/details/68946633 在配置<action> 时,可以在 name,class,meth ...

  8. Struts2(五.用户注册的实现及整合Action的配置方法)

    一.用户注册功能 register.jsp页面 若是jquery ajax方式提交给action,还要回到jquery,控制权在jquery若是表单方式提交给action,控制权交给action &l ...

  9. struts2:数据校验,通过Action中的validate()方法实现校验(续:多业务方法时的不同验证处理)

    前文:struts2:数据校验,通过Action中的validate()方法实现校验,图解 如果定义的Action中存在多个逻辑处理方法,且不同的处理逻辑可能需要不同的校验规则,在这种情况下,就需要通 ...

随机推荐

  1. new、virtual、override

    我们先看下面一段程序: public class Father { public void Run0() { Console.WriteLine("Father.Run0"); } ...

  2. php随机获取数组里面的值

    srand() 函数播下随机数发生器种子,array_rand() 函数从数组中随机选出一个或多个元素,并返回.第二个参数用来确定要选出几个元素.如果选出的元素不止一个,则返回包含随机键名的数组,否则 ...

  3. Codeforces 975 前缀和二分算存活人数 思维离直线速度相同判平行

    A /* Huyyt */ #include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; map< ...

  4. 单调队列优化DP || [Poi2014]Little Bird || BZOJ 3831 || Luogu P3572

    题面:[POI2014]PTA-Little Bird 题解: N<=1e6 Q<=25F[i]表示到达第i棵树时需要消耗的最小体力值F[i]=min(F[i],F[j]+(D[j]> ...

  5. vscode sftp插件的使用

    1.在扩展中搜索 sftp 并下载安装: 2.F1调出命令窗口输入 sftp 点击 SFTP:Config : 3.编辑 sftp.json 文件并保存会在当前工程下形成 sftp.json 文件 4 ...

  6. inotify.sh脚本范例

    inotify.sh脚本范例       [root@A-Server58 ~]# cat /server/scripts/inotify.sh#!/bin/bash#parahost01=192.1 ...

  7. org.springframework.web.servlet.view.ContentNegotiatingViewResolver

    restful服务中一个重要的特性就是一种资源可以有多种表现形式,在springmvc中可以使用ContentNegotiatingViewResolver这个视图解析器来实现这种方式. 描述资源的三 ...

  8. 输出到Excel

    HSSFWorkbook oBook = new HSSFWorkbook(); NPOI.SS.UserModel.ISheet oSheet = oBook.CreateSheet(); #reg ...

  9. layui 源码解读(部分)

    <!DOCTYPE html> <head> </head> <body> <input type="button" id=& ...

  10. linux下为已经编译好的php环境添加mysql扩展(php安装完成后如何添加mysql扩展)

    问题背景 平常我们都是先安装mysql,然后才能去安装php.假如先安装php,后安装mysql,由于php需要连接mysql,因而在php引擎中需要配置使用mysql.so扩展.这时需要手动编译生成 ...