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条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP