Topic: 請教Servlet的拋出錯誤信息處理(急﹗﹗)

  Print this page

1.請教Servlet的拋出錯誤信息處理(急﹗﹗) Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-07 15:17

我在web.xml里設置
<error-page>
    <error-code>500</error-code>
    <location>/common/alert.jsp</location>
  </error-page>
  <error-page>
    <exception-type>Exception</exception-type>
    <location>/common/alert.jsp</location>
  </error-page>
  <error-page>
    <exception-type>ServletException</exception-type>
    <location>/common/alert.jsp</location>
  </error-page>

然后在servlet里面
throw new ServletException("你操作的記錄已經被更改請從新打開再操作﹗");
結果alert.jsp并沒有攔截到exception

如何在servlet處理錯誤信息
類似jsp里的<%@ page errorPage="/common/alert.jsp" %>

2.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-07 15:33

補充﹕我用的是Tomcat4.1.24
<%@ page errorPage="/common/alert.jsp" %>
可以正常攔截jsp里面拋出的Exception,
在web.xml設置了<error-page>無法攔截到exception
而是被tomcat的默認錯誤頁攔截了并printStatrace很長很不好看。

3.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: drum
Posted on: 2003-07-07 15:58

<error-page>
<exception-type>ServletException</exception-type>
<location>/common/alert.jsp</location>
</error-page>
改为
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/common/alert.jsp</location>
</error-page>

4.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-07 17:05

非常感謝﹗﹗﹗

5.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: drum] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-07 17:11

drum wrote:
<error-page>
<exception-type>ServletException</exception-type>
<location>/common/alert.jsp</location>
</error-page>
改为
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/common/alert.jsp</location>
</error-page>

依舊無法攔截
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: 你操作的記錄已經被更改請從新打開再操作﹗
  at pmts.servlet.cwhandle.doGet(cwhandle.java:55)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

6.依舊無法攔截 [Re: drum] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-07 17:23

drum wrote:
<error-page>
<exception-type>ServletException</exception-type>
<location>/common/alert.jsp</location>
</error-page>
改为
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/common/alert.jsp</location>
</error-page>

依舊無法攔截

7.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: jbwang
Posted on: 2003-07-07 17:54

alert.jsp
<% page isErrorPage="true"%>(应该是这么写的吧?)
有这么一句吗?指定该jsp处理错误的.

8.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: jbwang] Copy to clipboard
Posted by: drum
Posted on: 2003-07-07 18:11

应该没有问题啊。
to jbwang
如果,alert.jsp只处理servlet抛出的例外是不用加isErrorPage属性的。
不过edgeloner 肯定加了这句,因为它捕获到了其他jsp页面抛出的例外。

再有
<error-page>
<exception-type>Exception</exception-type>
<location>/common/alert.jsp</location>
</error-page>
根本不起任何作用,不过加上也不会影响什么。

9.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: jbwang
Posted on: 2003-07-08 08:39

那是server设置成了调试模式了吗?

10.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-08 09:46

非常感謝﹐用普通htnl文件已經可以攔截到了﹐
不過這jsp里如何捕捉ServletException?
我都是因為這里有問題所以才沒有攔截到。

11.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: jbwang
Posted on: 2003-07-08 09:57

什么意思?

解释具体一些可以吗?
我没有搞懂.

12.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-08 10:01

如何在jsp捕捉sevlet拋過來的SevletException并顯示出來﹖

13.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: Andarkley
Posted on: 2003-07-08 10:03

exception object預設是抓javax.servlet.jsp.jspException
所以JSP扔出來的沒問題
Servlet扔出來的要另外處理才行
exception = (Throwable)request.getAttribute("javax.servlet.error.exception");

14.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: edgeloner] Copy to clipboard
Posted by: jbwang
Posted on: 2003-07-08 10:10

应该是jsp的隐含变量exception吧.

15.Re:請教Servlet的拋出錯誤信息處理(急﹗﹗) [Re: Andarkley] Copy to clipboard
Posted by: edgeloner
Posted on: 2003-07-08 10:26

Andarkley wrote:
exception object預設是抓javax.servlet.jsp.jspException
所以JSP扔出來的沒問題
Servlet扔出來的要另外處理才行
exception = (Throwable)request.getAttribute("javax.servlet.error.exception");

非常感謝﹗問題解決。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923