http://hi.baidu.com/yingshuishui1/item/c6a1610ad1b4851bebfe3870
来源:互联网 发布:天道留学 知乎 编辑:程序博客网 时间:2024/04/30 15:45
Struts1 config.xml基本配置导致抛出异常的原因分析
几种在struts-config.xml中经常由于粗心导致的配置错误
1 在action-mapping中的path属性中没有匹配到请求url的对应action时,一般会抛出如下异常Java代码- org.apache.struts.chain.commands.InvalidPathException:
- No action config found for the specified url
可能是由于没有设置该<action>或者没有正确设置<action>中的path属性。
2 在<action>中如果没有配置name属性或者name属性配置错误导致在<form-beans>中找不到匹配的元素时,struts容器并不会抛异常,而是很简单的将一个null值作为form参数传递给了Action.execute()方法。Xml代码- <action path="/login" type="com.element.LoginAction" name="loginForm">
- <forward name="loginSuccess" path="/loginSuccess.jsp"></forward>
- <forward name="loginFailure" path="/loginFailure.jsp"></forward>
- </action>
即:
Java代码- public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
方法中的form被struts传入null值,在接下来的form转型并不会抛异常,因为(LoginForm)null是合法的。但是在后面的对loginform存取参数的代码中一定会抛出NullPointException异常。
如果在一次request请求中不需要提交附加数据,那么就不需要在<action>中配置name属性。
3 表单上的控件name属性和formbean中的属性名不匹配的时候,struts就不会设置form中的那个不匹配的属性了,这样在转型后存取参数的时候就会发生NullPointException异常。Html代码- <form action="<%=request.getContextPath()%>/login.do">
- username:<input name="username1" type="text"/><br/>
- password:<input name="password" type="password"/><br/>
- <input name="test" type="text"/>
- <input type="submit" value="登陆">
- </form>
但是如果name属性匹配到formbean中的属性,但是表单控件并没有输入,则浏览器会发出
Html代码- login.do?username=&password=xxx
之类的url请求,这时struts会讲formbean中的属性设置为“”空字符串,而对于其他类型的属性,例如int型,就会设置成0值。
此文章转自:http://hi.baidu.com/yingshuishui1/item/c6a1610ad1b4851bebfe3870
- http://hi.baidu.com/yingshuishui1/item/c6a1610ad1b4851bebfe3870
- http://hi.baidu.com/luckystreet/item/c4a6f10c417db2f1a11034ec
- http://hi.baidu.com/3582077/item/e1ae928ba93b8c55e63d190a
- http://hi.baidu.com/heyg/blog/item/9ca8dcc4785706cb38db4937.html
- http://hi.baidu.com/suwey/blog/item/9b4d72c238e7e334e5dd3bc0.html
- http://hi.baidu.com/lhcling/blog/item/0e3e60cfa55aca3ef8dc61c0.html
- http://hi.baidu.com/jmugis/blog/item/ad03b11f89a25ef6e1fe0b18.html
- http://hi.baidu.com/nnffnn/blog/item/e84cd15c1d893943faf2c07c.html
- http://hi.baidu.com/herowzz/blog/item/286e3c546eb23157574e0077.html
- http://hi.baidu.com/kacaca/blog/item/1fd412d644f9f42907088b89.html
- http://hi.baidu.com/sophie198384/blog/item/26960501e9a757021d9583a0.html
- http://hi.baidu.com/123az/blog/item/f482f51980e8e04642a9ad6c.html
- http://hi.baidu.com/zonesky/blog/item/328d9807043c2ccb7a894717.html
- http://hi.baidu.com/shasha1918/blog/item/ee5fdf18f049fc0235fa4187.html
- http://hi.baidu.com/620734263/blog/item/513a102fa4a551424ec226f8.html
- http://hi.baidu.com/jisu3d/blog/item/f7ad4fd0ac727526960a1652.html HLSL
- http://hi.baidu.com/jsjlx2004/blog/item/74409ccbd5741619be09e6a1.html
- http://hi.baidu.com/edeed/blog/item/3e92277f7a15830028388aec.html
- c/c++中#include <>与#include""区别
- Jquery+Ajax
- property属性总结
- 见证,邂逅,感谢一路有你
- GridView上传到服务后编辑和,删除,取消按钮变为英文
- http://hi.baidu.com/yingshuishui1/item/c6a1610ad1b4851bebfe3870
- maven编译error:Could not find tool 'aapt'. Please provide a proper Android SDK directory path as confi
- 【discuz】G变量的使用
- Win7环境下VS2010配置Cocos2d-x-2.1.4最新版本的开发环境(亲测)
- 偏方
- RMAN 备份与恢复 实例 .
- 异步加载图片AsyncTask
- poj 3087 模拟
- Exchange Web Service (EWS) API 使用笔记