zrzking 2008-12-30 20:37
浏览 1654
已采纳

Tomcat errorPage 配置问题

JDK版本:jdk1.6.0

 

Tomcat 版本:apache-tomcat-6.0.18

  <error-page>
    <error-code>401</error-code>
    <location>/401.htm</location>
  </error-page>
  <error-page>
    <error-code>403</error-code>
    <location>/403.htm</location>
  </error-page>
  <error-page>
    <error-code>404</error-code>
    <location>/404.htm</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/500.htm</location>
  </error-page>
 <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/errorProcess.jsp</location>
</error-page>

 

模拟出错场景:客户发送请求在先

                     客户端得到的新闻链接存在       恰好后台管理员客户单击连接前删除了该新闻               

                     向服务器端请求的路径如下:detail.jsp?i=402881e41e743103011e7447faa90005

                     新闻详细页detail.jsp中处理了该请求 会调用service类处理 在不存在该记录时 hibernate会抛出NotObject异常

疑惑:异常本应该本tomcat截获并处理 跳转到/errorProcess.jsp 进行友好提示 但是事实是:仍会跳转到detail.jsp页面 可想而知这个页面的遭遇是面目全非

期待大家的回复  

 

 

 


问题补充:
throne212

hibernate层如下:

public Object findByModelId(Class model,String modelId) {

return this.getHibernateTemplate().load(model, modelId);

}

spring层如下:

public Object findByModelId(Class model,String modelId) throws Exception {

return getBaseDao().findByModelId(model,modelId);

}

我们的整个架构都是将异常集中在spring层进行catch



现在的问题是  整个项目已经接近尾声 需要一个通用的方法

如果为每个dao都增加异常处理 这个工作量相当大  请提供一个简单实用的方法 谢谢

  • 写回答

3条回答 默认 最新

  • throne212 2009-01-02 09:35
    关注

    [quote]load

    public Object load(Class theClass,
    Serializable id)
    throws HibernateException

    Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. This method might return a proxied instance that is initialized on-demand, when a non-identifier method is accessed.
    
    You should not use this method to determine if an instance exists (use get() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.
    
    Parameters:
        theClass - a persistent class
        id - a valid identifier of an existing persistent instance of the class 
    Returns:
        the persistent instance or proxy 
    Throws:
        HibernateException[/quote]
    

    这是从hibernate api 文档中session的load方法的介绍,人家告诉你了:你不能用这个方法来判定实体是否存在,而应该用get()替代。
    我试验了一下,
    get()的话,如果不存在,返回的是null
    load()则返回的是一个代理对象,如果你不使用这个对象,不会有任何问题,如果访问这个对象,就会有一个异常,如:org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [test.UserTable#920]

    所以,我建议你使用get。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析