struts2.5.2 通配符问题_亲测有用
2024-08-31 02:36:15
学了一段时间struts2,跟着教程做,但发现struts2的版本不同,很多东西的使用是有差异的。例如之前遇到的创建sessionFactory的方式就跟之前版本有着明显的差异。今天又遇到一个问题,那就是通配符的使用。
问题:若不使用通配符,可以找到相对应的action,而使用通配符就会报错,找不到actionmapping之内的错,找不到action。
问题原因: struts2.5 为了增加安全性,在 struts.xml 添加了这么个属性:<global-allowed-methods>regex:.*</global-allowed-methods>
解决:
<?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> <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant> </struts>
1.首先,注意头部信息,这个应该是用来指定文件中允许使用那些标签。
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd">
2.加上下面这句。
<global-allowed-methods>regex:.*</global-allowed-methods>
或者(不加上面这句),在action中加上指定允许调用的方法的语句:
<allowed-methods>login,logout</allowed-methods>
最新文章
- 初试WIX加SQL LocalDB
- C--变量的命名规则
- HTTP与AJAX深入揭秘,不使用AJAX实现页面无刷新
- springMVC乱码问题-转
- 【转载】ODBC, OLEDB, ADO, ADO.Net的演化简史
- jQuery实现登录提示
- openstack 实例迁移
- HDU(搜索专题) 1000 N皇后问题(深度优先搜索DFS)解题报告
- auto space advisor
- 找不到方法: Int32 System.Environment.get_CurrentManagedThreadId() .
- Ajax笔记 XHR XMLHttpRequest
- strlen出错
- flask第一章 flask启动 路由视图 FlaskRequest jinja2 FlaskSession
- Eclipse Tomcat部署web项目时出现There are no resources that can be added or removed from the server解决办法
- NOIP2017题解
- 关于Error during managed flush [Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]错误
- .Net MVC发布出错 Server Error in &#39;/&#39; Application.
- python pbr 打包
- Linux命令——磁盘管理
- Restful api 防止重复提交