HTTP Status 404 - No result defined for action EmployeeAction and result input - struts2类似异常解决及原因剖析
来源:互联网 发布:淘宝里的广告商品好吗 编辑:程序博客网 时间:2024/05/22 07:45
根据提示在struts.xml相应位置处加上了返回类型为input的,蓝色部分,就好了,其实这种解决方法治标不治本。
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="main" extends="struts-default"> <action name="employee_list" method="list" class="EmployeeAction"> <result>/jsp/employee.jsp</result> <result name="input">/jsp/employee.jsp</result> </action> <action name="employee_create" method="create" class="EmployeeAction"> <result name="success" type="redirectAction">employee_list</result> <result name="input">/jsp/employee.jsp</result> </action> </package></struts>
public String list(){employees=EmployeeManager.getEmployees();return SUCCESS;}
之前struts.xml中返回类型,只有一个返回success即没加蓝色部分时就出现了标题中的错误。加了之后,就好了。是struts2从程序健壮性方面考虑,要求加上结果不是SUCCESS的处理。由于框架struts2拦截器的处理后,看似404的问题,其实不是简单的找不到路径的问题,我们不应该只是如上面简单地加上<result name="input">/some.jsp</result>,关键我们我弄清楚struts2的拦截机制到底做了什么处理。出现标题中的错误的根本原因在于struts2处理数据时类型转换失败。
具体解释如下:
struts2把请求的参数映射到action属性的工作由parameters拦截器负责,它是默认的defaultStack拦截器栈的一员。所有的请求参数都是String类型,但并非所有的action属性都是String类型,所以每一种非String类型的action属性都需要对相应的请求参数进行类型转换。parameters拦截器使用了OGNL AP来达到这一目的。准确地说,它就是ognl.OgnlRuntime类,这个类又依赖于java 反射。对每一个需要被设置的属性,OgnlRuntime将为之创建一个java.lang.reflection.Method对象,并调用它的invoke方法。
当然类型转换不总是成功,因为用户输入的数据可能无法转换为对应的action属性。
重点来了:如果类型转换失败了,struts2为我们准备了什么样的解决方案呢?
在因为类型转换失败而发生错误时,struts不必停下了,它有两种选择,具体选择哪一种将取决于你的action类是否实现了com.opensymphony.xwork2.ValidationAware接口。
如果某个action类没有实现ValidationAware接口,struts在遇到类型转换错误时仍会继续调用其动作方法,就好像什么问题都没有发生那样。
如果某个action类实现ValidationAware接口,struts在遇到类型转换错误时将不调用其动作方法:struts将检查相关action元素的声明是否包含一个input结果。如果是,struts将把控制权转交给那个result元素;如果找不到这样的结果,struts将抛出一个异常。这就是为什么有时候会抛出如题的异常的原因。
- HTTP Status 404 - No result defined for action EmployeeAction and result input - struts2类似异常解决及原因剖析
- HTTP Status 404 - No result defined for action EmployeeAction and result input - action类似异常解决及原因剖析
- struts2 上传文件 HTTP Status 404 - No result defined for action.....and result input
- HTTP Status 404 - No result defined for action org.csun.ns.action.NtHomesAction and result input
- HTTP Status 404-no result defined for action com.huida.action.LinkManAction and result input
- HTTP Status 404 - No result defined for action and result input
- HTTP Status 404 - No result defined for action …… and result input。
- HTTP Status 404 - No result defined for action XXX and result input
- HTTP Status 500 - No result defined for action com.action.goodsAction and result input
- Struts2异常:No result defined for action cn.itcast.oa.struts2.action.DepartmentAction and result input
- Struts2 异常:no result defined for action result input
- struts2 No result defined for action.....and result input
- Struts2:No result defined for action XXX and result input
- [SSH]Struts2 -- No result defined for action and result input
- struts2 no result defined for action xxxx and result input
- No result defined for action and result input异常
- “HTTP Status 404 - No result defined for action ****** and result result”错误解决方法
- “HTTP Status 404 - No result defined for action ****** and result result”错误解决方法
- Rose 2003 安装“java.lang.NullPointerException”解决方法
- [C++] friend class
- Git And Remote Repositories
- Android应用中通过AIDL机制实现进程间的通讯实例
- 一组C++中的字符串与数字的互转函数
- HTTP Status 404 - No result defined for action EmployeeAction and result input - struts2类似异常解决及原因剖析
- 直接插入排序
- configure.ac:261 error:must install xorg-macros 1.1.3 or later before running autoconf/autogen
- mysql创建序列
- 使用 OpenRowSet 和 OpenDataSource 访问 Excel 97-2007
- 懒惰的人生,注定一事无成
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET
- Linux上的文件操作
- 进销存之“进”