strust框架下默认Action default-action-ref 出现HTTP Status 500错误
来源:互联网 发布:java导出excel表格poi 编辑:程序博客网 时间:2024/05/18 10:52
默认Action default-action-ref会与通配符* _ *发生冲突
一、错误代码示例
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <package name="*" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-action-ref> <action name="index"> <result>/error.jsp</result> </action> <action name="*_*" method="{2}" class="com.imooc.action.{1}Action"> <result>/result.jsp</result> <result name="add">/{2}.jsp</result> <result name="update">/{2}.jsp</result> </action> </package>
二、发生错误HTTP Status 500
三、修改之后代码
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <package name="*" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-action-ref> <action name="index"> <result>/error.jsp</result> </action> <action name="helloworld_*" method="{1}" class="com.imooc.action.HelloWorldAction"> <result>/result.jsp</result> <result name="add">/{1}.jsp</result> <result name="update">/{1}.jsp</result> </action> </package>
四、参考文章
这段时间学习struts2 发现同时用默认action和通配符 *_*会有冲突。 最后我的解决方法是不写*_*,稍微麻烦一点,就是把你的{1}写死,后面的用*,这样就没问题了,例如你写的是一个UserAction,配的时候name="User_*",这样写可能会更好些,看的更清晰,也不会影响default-action-ref的使用。<package name="default" namespace="/" extends="struts-default"><!-- 用default-action-ref 可以实现struts中的默认action,就是在服务器找不到用户浏览器中的action时都会跳到该默认action--><default-action-ref name="index"></default-action-ref> <action name="index"> <result>/index.jsp</result> </action><!-- 使用默认action时不能有下面的通配符设置,不然在匹配时会报错<action name="*_*" class=".struts.action.{1}Action" method="{2}"> <result>/{1}_{2}_success.jsp</result> </action>--><!-- 但是可以使用user*或者user_*这种通配符--><action name="user_*" class="struts.action.UserAction" method="{1}"> <result>/user_{1}_success.jsp</result></action></package>
五、参考意见
使用通配符* _ * 会发生这样的错误,但是使用 * _ * _ * 和通配符HelloWorld_ * 不会发生错误。
应尽量减少使用 * _ * 的使用
阅读全文
0 0
- strust框架下默认Action default-action-ref 出现HTTP Status 500错误
- Struts2---->default-action-ref
- default-action-ref访问默认action不会执行action的代码问题解决
- <default-action-ref>的用法
- struts.xml不在默认位置,导致出现HTTP Status 404 - There is no Action mapped for namespace [/] and action name [
- Struts2设置默认action <default-action-ref name="index" />失效
- HTTP Status 500 - Unable to instantiate Action
- 关于 default-action-ref 的一个BUG
- struts.xml中的default-action-ref问题
- struts2中对于default-action-ref配置
- 关于default-action-ref的思考
- 关于global-results与default-action-ref
- struts.xml中的default-action-ref问题
- struts 中default-action-ref的问题
- 关于struts2中的default-action-ref
- struts.xml中的default-action-ref问题
- Struts2当调用action时出现HTTP Status 404 问题解决
- eclipse运行ssh项目出现"HTTP Status 500 - Unable to instantiate Action"
- golang通道中 nil通道 close通道的特性点
- Materail Design 入门(九)—— NavigationView的使用
- iOS 钥匙串相关操作
- PHP7.0 报错Class 'XMLWriter' not found
- 深入了解java虚拟机之GC回收机制
- strust框架下默认Action default-action-ref 出现HTTP Status 500错误
- linux 下的两种软件安装方式 —— 源码(编译、安装),编译好的二进制(直接安装)
- 基于nginx的C模块代码实现获取POST请求参数并回传给客户端
- API函数操作COM口
- 【获奖公布】征文 | 你会为 AI 转型么?
- https的配置以及php中判断问题
- 22. Spring Boot 拦截器HandlerInterceptor【从零开始学Spring Boot】
- SSH 显示中文乱码
- 你可能不知道的关于golang 的10件事情