假设我们在 Struts 2、Hibernate、MySQL 中开发了一个网站,并且我们在try/catch
这里添加了几个块,这些块包含通过 Hibernate 进行的数据库调用。
我的问题是:
在 catch 块内,我正在向记录器发送适当的消息。在这里我们不能将
System.out.println
其用作网页,还有什么可以提醒用户异常?作为测试的一部分,我更改
hibernate.cfg.xml
并输入了错误的数据库密码,以模拟数据库崩溃的场景。
正如我所料它抛出了错误:
javax.servlet.ServletException: Filter execution threw an exception
java.lang.NoClassDefFoundError: com_cenqua_clover/CoverageRecorder
my.com.employee.<init>(employee.java:29)
com.action.employeeAction.<init>(employeeAction.java:23)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:513)
java.lang.Class.newInstance0(Class.java:355)
java.lang.Class.newInstance(Class.java:308)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:119)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)
com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109)
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.20 logs.
从用户的角度来看,这是不可取的权利,那么如何解决这些问题。我正在使用 Eclipse Juno、Windows XP、MySQL 5.5。