struts2.5通配符的问题

本文介绍在Struts2.5中使用通配符遇到的问题及解决方案,由于新增的安全特性,需在配置文件中添加全局通配符标签<global-allowed-methods>regex:.*</global-allowed-methods>。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

struts每个版本都会有一些新特性,今天升级struts2.5遇到一个通配符的问题,通过查找各方资料终于解决了,现做个记录。
struts2.5使用通配符报找不到相应action的错误,不用通配符就正常。

问题原因:struts2.5增加了安全性,在package中需要添加全局标签 <global-allowed-methods>regex:.*</global-allowed-methods>
或者在action中添加 <allowed-methods>addUser,addUser2</allowed-methods>指定通配符允许调用的方法。
建议使用全局通配符标签,因为在action中配置需要增加大量的工作量降低效率。

<?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>

<package name="default" namespace="/" extends="struts-default">
   <global-allowed-methods>regex:.*</global-allowed-methods>
 <action name="helloworld" class="com.imooc.action.HelloWorldAction">
      <result>/result.jsp</result>
      <result name="add">/add.jsp</result>
      <result name="update">/update.jsp</result>
 </action>

</package>
</struts>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值