Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Servlet JSP异常/错误处理_Java_Jsp_Servlets - Fatal编程技术网

Java Servlet JSP异常/错误处理

Java Servlet JSP异常/错误处理,java,jsp,servlets,Java,Jsp,Servlets,我正在尝试使用JSP errorpage配置处理异常。但它失败了。请指出我哪里做错了。 这不是任何实时应用程序,我只是在尝试一个场景 初始jsp页面: page1.jsp <body> <form action="process.do" method="post"> <input type="Submit" /> </form> </body> <%@ page language="java" c

我正在尝试使用JSP errorpage配置处理异常。但它失败了。请指出我哪里做错了。 这不是任何实时应用程序,我只是在尝试一个场景

初始jsp页面:

page1.jsp

<body>
    <form action="process.do" method="post">
        <input type="Submit" />
    </form>
</body>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isErrorPage='true'%>
<html>
<head>
<title>Error Page</title>
</head>
<body>
    <%
        out.print("Error Message : ");
        out.print(exception.getMessage());
    %>
</body>
</html>
errorpage.jsp

<body>
    <form action="process.do" method="post">
        <input type="Submit" />
    </form>
</body>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isErrorPage='true'%>
<html>
<head>
<title>Error Page</title>
</head>
<body>
    <%
        out.print("Error Message : ");
        out.print(exception.getMessage());
    %>
</body>
</html>

这是我在下面博客链接上的一条评论中发现的

使用“errorpage”“iErrorPage”并在web.xml文件中声明错误页时存在严重问题,它在Internet Explorer版本6和7中无法正确显示,相反,它显示了自己的IE错误页,用于404页和内部服务器错误500。更好的方法是使用Spring异常处理并为Spring的异常处理程序定义默认错误视图。通过这种方式,您将在所有浏览器上获得一致的行为,因为错误页面将不会被视为错误页面,而是被视为另一个jsp页面。我花了很多时间用IE6解决这个错误,您可能会节省宝贵的时间。还有一种理论认为,如果错误页面的大小小于512字节,IE和chrome将显示自己的错误页面。我已经对此进行了测试,但在我的例子中,即使大小超过512字节,它仍然显示“InternalServerError-500”,唯一有效的解决方案是使用Spring异常处理


阅读更多信息:

谢谢。我试着从Chrome和Firefox上打开,结果一切正常。早些时候,我是从IE9运行的。惊讶当你解决实际问题时,我接受了答案。想知道这是如何依赖于浏览器的@prash这与:似乎可以通过延长页面来改变。谢谢@fgb:)事实上,IE奇迹般地抑制了错误,包括Javascript错误
SEVERE: Servlet.service() for servlet [servlet1] in context with path [/simpleServlet] threw exception [my custom exception message] with root cause
javax.servlet.ServletException: my custom exception message
    at com.examples.example.Servlet1.doPost(Servlet1.java:48)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)