http://hi.baidu.com/xogjghsfhjemorr/item/5aab56f5f2f220ed1b111f5c
来源:互联网 发布:免费胸卡制作软件 编辑:程序博客网 时间:2024/06/07 07:00
将Struts的Action方法中抛出的Exception信息显示在页面上的方法
1、定义一个ExceptionHandlerApp类,继承org.apache.struts.action.ExceptionHandler;
2、在ExceptionHandlerApp类中的execute方法中,将错误的Message写入attribute,并且处理发生错误时候,定向的错误页面。
如下:
public ActionForward execute(Exception ex, ExceptionConfig exCfg,
ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ServletException {
log.info("Error Catched by ExceptionHandlerImpl,Ex="
+ ex.getMessage());
request.setAttribute("error",ex.getMessage());
return mapping.findForward("error");
}
3、在struts配置文件中,加入处理标签。如果多个模块的struts应用系统,据试验应该在每个模块中都放置该标签,而不能仅仅在struts-config.xml中添加(好像这个文件,没多大用了)
struts-user-config.xml中,添加:
<global-exceptions>
<exception
key="error"
type="java.lang.Exception"
handler="com.lovefanx.framework.web.ExceptionHandlerImpl"/>
</global-exceptions>
4、在这个配置文件中struts-user-config.xml中,加入发生错误后,要显示的页面。
<global-forwards>
<forward name="error" path="/../error/error.jsp"/>
</global-forwards>
5、现实的错误界面error.jsp
<table width="50%" align="center" border="1">
<tr>
<td>系统错误信息:</td>
</tr>
<tr>
<td><bean:write name="error" /></td>
</tr>
</table>
6、Action类中的方法,不需要try--catch--,如果遇到抛出错误,会直接抛出,并且交给handler="com.lovefanx.framework.web.ExceptionHandlerImpl"处理。
7、如果struts使用spring+hibernate一起构建系统,那么spring的service类,建议将可能遇到的错误,抛出Exception即可,交给struts的action处理。而hibernate实现类,可以考虑不用处理exception了,这样比较简单。
- http://hi.baidu.com/xogjghsfhjemorr/item/5aab56f5f2f220ed1b111f5c
- 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
- 存储器映射文件
- 树结构的遍历
- SQLite使用小例
- Extjs中Form页面隐藏存值修改
- 性能
- http://hi.baidu.com/xogjghsfhjemorr/item/5aab56f5f2f220ed1b111f5c
- linux 前台进程 后台进程
- Myeclipse6.0实现JPA 创建
- Object.prototype.toString.call 与数组判断
- 圈圈usb cannot convert from 'BOOL (__thiscall CMyUsbHidTestAppDlg::* )(UINT,DWORD)' to 'LRESULT (__
- mfc 中的字符
- innodb 引擎数据恢复
- WS02-WSO2 Application server介绍
- html中 media的作用