Struts2中action注解使用异常
来源:互联网 发布:javascript 转义符 编辑:程序博客网 时间:2024/06/08 05:37
Struts2中action注解使用异常
异常展示
初学Struts2,简单串一遍Struts2的流程,实现如下功能:
需求:
浏览器发出/list请求,服务器响应到empList.jsp页面
流程设计
/list ---> StrustPrepareAndExecuteFilter --> EmpAction ---> Result (dispatcher)---> empList.jsp页面
流程实现
- 搭建Struts2环境 - struts2开发包和注解配置包(struts2-convention-plugin-2.3.31.jar) - struts.xml配置文件- 编写一个empList.jsp- 编写一个EmpListAction组件- 在web.xml配置StrustPrepareAndExecuteFilter控制器- 在EmpListAction中使用@Action、@Result、@ParentPackage、@NameSpace注解配置请求
工程结构如图
Emplist类如下:
@ParentPackage("struts-default") @Namespace("/") public class EmpList { /** * 员工列表 */ private List<Emp> emps; public List<Emp> getEmps() { return emps; } public void setEmps(List<Emp> emps) { this.emps = emps; } @Action(value = "/list", results = { @Result(name = "success", type = "dispatcher", location = "/emp.jsp") }) public String execute() { return "success"; } }
之前使用Struts.xml 配置,程序可以顺利进行,使用action的注解配置之后,请求发出之后出现404的异常,如下图所示:
很显然qingqiu并没有被映射到任何一个action,注解配置出了问题,查询资料后发现结果在struts2-convention-plugin-2.3.31.jar底层对action组件的映射规则上,打开Convention Plugin中struts-plugin.xml配置发现在struts-plugin.xml中,action的名称的映射是:
<constant name="struts.convention.action.suffix" value="Action"/> <constant name="struts.convention.action.disableScanning" value="false"/> <constant name="struts.convention.action.mapAllMatches" value="false"/> <constant name="struts.convention.action.checkImplementsAction" value="true"/> <constant name="struts.convention.default.parent.package" value="convention-default"/> <constant name="struts.convention.action.name.lowercase" value="true"/> <constant name="struts.convention.action.name.separator" value="-"/> <constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/> <constant name="struts.convention.package.locators.disable" value="false"/> <constant name="struts.convention.package.locators.basePackage" value=""/> <constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.*"/> <constant name="struts.convention.relative.result.types" value="dispatcher,velocity,freemarker"/> <constant name="struts.convention.redirect.to.slash" value="true"/> <constant name="struts.convention.action.alwaysMapExecute" value="true"/> <constant name="struts.mapper.alwaysSelectFullNamespace" value="true"/>
这个是默认的配置,就是去掉Action结尾的单词,把剩余的都转化为小写,然后在中间加上“-”,
例如:
AdminUserAction映射后变成:admin-user.action,这样的映射规则个人感觉很别扭,想用原来的习惯映射成:adminUser.action
将类名修改为EmpListAction之后程序顺利运行。
爬坑经验:
为避免出错,按照规范,action组件类名以Action结尾。
具体的映射规则,有待以后研究。
参阅http://blog.sina.com.cn/s/blog_3e8afd2e0100cp76.html
阅读全文
0 0
- Struts2中action注解使用异常
- struts2中使用注解配置Action
- struts2中使用注解配置Action
- Struts2 注解中跳转 action
- Struts2 注解中跳转 action
- Struts2 注解中跳转 action
- Struts2 Action中使用注解注入调用service
- struts2中Action配置之注解配置
- struts2使用注解--ACTION中的应用
- struts2使用注解--ACTION中的应用
- struts2 使用注解形式开发Action步骤
- Struts2使用19 -- 注解配置1 -- Action注解配置
- struts2 action中使用AJAX
- 【struts2】action中使用通配符
- 【struts2】action中使用通配符
- Struts2的convention插件,在步骤中使用Action注解跳转到其他jsp页面
- Struts2---action-基于注解
- Struts2异常处理之在Action中捕获异常
- 32位操作系统与64位操作系统的区别
- ubuntu 命令行模式连接wifi
- POJ
- matlab做数据拟合
- Android Gradle打包
- Struts2中action注解使用异常
- HDU 2199 Can you solve this equation? 牛顿迭代法 || 二分
- hadoop的安装
- 合并区间-LintCode
- 矩阵的乘积【水题】
- 通过字节流复制粘贴文档
- hdu 5894 (组合)
- Fibonacci (矩阵快速幂)
- 仿京东首页的京东快报,自动向上滚动的广告条