编程社区 » web开发 » 这个问题离奇~~~~就是关于设置errorPage的

这个问题离奇~~~~就是关于设置errorPage的


luoxu0501



 发表:

这个问题离奇~~~~就是关于设置errorPage的


三个页面,都非常简单。


调试的时候很奇怪,说 无法显示网页,真晕,在刷新,也能把例外的字符串输出来。虽然我可以通过别的方法实现。但是为什么这个不通啊,请各位帮忙指点指点。

<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<form name="form1" method="post" action="3.jsp">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="28">被除数</td>
<td><input type="text" name="str1"></td>
</tr>
<tr>
<td height="28">除数</td>
<td><input type="text" name="str2"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="计算"></td>

</tr>
</table>
</form>

</body>
</html>






<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="error.jsp"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%

int a=0,b=0,c=0;
try{
a=Integer.parseInt(request.getParameter("str1"));

}catch(NumberFormatException e){throw new NumberFormatException("被除数非整数");
}
try{
b=Integer.parseInt(request.getParameter("str2"));
}catch(NumberFormatException e){throw new NumberFormatException("除数非整数");}
c=a/b;
out.println(a+"/"+b+"="+c);


%>
<a href="javascript:history.back();">返回</a>
</body>
</html>









<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" isErrorPage="true" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%=exception.toString()%>
</body>
</html>




当然如果不例外的话,程序正常。谢谢大家。


luoxu0501
回复:

晕,怎么20分?什么意思啊

yuzhenhao
回复:

第一个页面,
没有设置 ERRORPAGE属性。

luoxu0501
回复:

第一个页面设置了以后,还是的阿

无法显示网页
您要访问的网页有问题,无法显示。

--------------------------------------------------------------------------------

请尝试以下操作:

打开 localhost:8090 主页,然后查找指向您感兴趣信息的链接。
单击刷新按钮,或以后再试。

单击搜索,寻找 Internet 上的信息。
也可查看相关站点列表。




HTTP 500 - 内部服务器错误
Internet Explorer

luoxu0501
回复:

还不行啊

rongdajian
回复:

经过我的测试,这个程序完全没有问题!
真的,当除数为0的时候能正确的抛出“java.lang.ArithmeticException: / by zero ”异常,如果是字符也能正常的抛出!因此没有问题哈!我用的是Tomcat5.0.28哈!你再看看再找找原因!好吧!

xifo79
回复:

你的应用服务器没有正常启动,或者端口号不是8090,仔细检查下你的服务器吧。

luoxu0501
回复:

我的应用服务器怎么检查阿?我用的也是Tomcat5.0.28,我哭啊。。

我也感觉可能我的配置上有些问题。但是说不出来哪里。我写了两个javabean, 几乎一样,可是一个能用,一个不能用,会是什么错误啊。真是心焦 。。。

luoxu0501
回复:

帮帮我阿

stevensinclair
回复:

楼主,你要改的端口号在\Tomcat 5.5\conf这个路径里的server.xml里改就行了.

gefengxztg
回复:

这个程序真的没问题吗
我测试也不成功呢
try{
a=Integer.parseInt(request.getParameter("str1"));//此处不会引发“被除数非整数”异常

}catch(NumberFormatException e){throw new NumberFormatException("被除数非整数");
}
try{
b=Integer.parseInt(request.getParameter("str2"));//此处不会引发“除数非整数”异常
}catch(NumberFormatException e){throw new NumberFormatException("除数非整数");}
c=a/b;//算术异常有可能在这里引发,但没捕捉
我不是很懂java异常机制啊,继续学习!!

gefengxztg
回复:

改成这样成功了
3.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" isErrorPage="false" errorPage="error.jsp"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
int a=0,b=0,c=0;
a=Integer.parseInt(request.getParameter("str1"));
if(a <= 0) throw new NumberFormatException("被除数非整数");
b=Integer.parseInt(request.getParameter("str2"));
if(b <= 0) throw new NumberFormatException("被除数非整数");
c=a/b;
out.println(a+"/"+b+"="+c);
%>
<a href="javascript:history.back();">返回</a>
</body>
</html>



error.jsp:

<%@ page contentType="text/html; charset=gb2312" language="java" isErrorPage="true" import="java.io.*"%>
<html>
<head>
<title>错误页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
出错了!<br>
发生了以下的错误:
<br>
<%=exception.getMessage()%><br><hr>
<%
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
exception.printStackTrace(pw);
out.println(sw);
%><br>
</body>
</html>

gefengxztg
回复:

StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
exception.printStackTrace(pw);
out.println(sw);
这几句一句都不能少!!
不是很了解

luoxu0501
回复:

我哭,,,,,我怎么还是那样阿。。。

无法显示网页
您要访问的网页有问题,无法显示。

--------------------------------------------------------------------------------

请尝试以下操作:

打开 localhost:8090 主页,然后查找指向您感兴趣信息的链接。
单击刷新按钮,或以后再试。

单击搜索,寻找 Internet 上的信息。
也可查看相关站点列表。




HTTP 500 - 内部服务器错误
Internet Explorer




为什么你们都调得好就我的不行。。。。。。。。。。。。难过。。

luoxu0501
回复:

谢谢楼上的,你们费心了。。

我现在委曲求全,把端口号改成了8080了。。。但是还是没有用。。。

luoxu0501
回复:

<%@ page contentType="text/html; charset=gb2312" language="java" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<form name="form1" method="post" action="3.jsp">
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="28">被除数</td>
<td><input type="text" name="str1"></td>
</tr>
<tr>
<td height="28">除数</td>
<td><input type="text" name="str2"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="计算"></td>

</tr>
</table>
</form>

</body>
</html>









<%@ page contentType="text/html; charset=gb2312" language="java" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%

int a=0,b=0,c=0;
try{
a=Integer.parseInt(request.getParameter("str1"));

}catch(NumberFormatException e){out.println("被除数非整数");
}
try{
b=Integer.parseInt(request.getParameter("str2"));
}catch(NumberFormatException e){out.println("除数非整数");}
c=a/b;
out.println(a+"/"+b+"="+c);


%>
<a href="javascript:history.back();">返回</a>
</body>
</html>

错误是HTTP Status 404 - /test/

--------------------------------------------------------------------------------

type Status report

message /test/

description The requested resource (/test/ ) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.28

pigo
回复:


IE在默认的“显示http友好信息”选项中加入了特定功能:如果自定义出错页面的输入字节数小于512字节,将继续显示它的http友好信息

解决办法,就是在出错页面里多加点东西。

你把你的errors.jsp加上一些空格,让它在输出时能大于512字节,就可以了。


http://www.google.cn/search?hl=zh-CN&newwindow=1&q=resin+ie+%E6%98%BE%E7%A4%BAhttp%E5%8F%8B%E5%A5%BD%E4%BF%A1%E6%81%AF&btnG=%E6%90%9C%E7%B4%A2&meta=




pigo
回复:

相关讨论:

http://www.caucho.com/support/resin-interest/0005/0373.html

thinking1985
回复:

你是不是没开tomcat啊

tianxiashuai
回复:

建议再配一台服务器做对比测试!

luoxu0501
回复:

我只有一台机器阿。。我加了很多空格,还有字,还是不行啊。。。好像不能抛出例外,不能正常受到例外。。。

luoxu0501
回复:

不知道怎么解决,烦死了

luoxu0501
回复:

dddddddddddddd

yown
回复:

是IE的设置有问题。参见 pigo(不成功,便成练习) ( 两星(中级)

yiweiposer
回复:

在error.jsp中加:
<%
response.setStatus(HttpServletResponse.SC_OK);
%>
试试!

yiweiposer
回复:

你把
c=a/b;
out.println(a+"/"+b+"="+c);
改为:
try{
c=a/b;
out.println(a+"/"+b+"="+c);
}catch(Exception exp){
System.out.println("this is Exception:"+e.toString());

}


------------------------------
这种异常好像tomcat 不捕捉.只能写try catch
在catch 中加response.sendRedirect("error.jsp");
我也碰到过这种问题。
异常:NoSuchElementException
能try catch 到.如果不try catch, tomcat 的logs是没有记录的。
errorPage也不会发挥作用。
所以我个人认为,errorPage只会对tomcat能捕捉到的异常发挥作用.
好像很多RuntimeException,tomcat都不能捕捉到

luoxu0501
回复:

哈哈,我成功了,太开心了。。。。跟大家分享。。。pigo(不成功,便成练习)说的解决办法是不行的,但是问题被你找对了,因为我加了很多字也没用,最后我把ie的设置,显示http友好信息前面的勾拿掉就成功了!!!!!!!!!

看了yown(yong) 的回复,让我才想到去修改设置,yeah~~~~~~~~~~~

谢谢各位的指导。


相关文章
求助!关于简繁体混合查询
一个关于JAVABEAN的编译问题
朋友们:帮个忙!!!(有关jsp的问题)
动态下拉式菜单 --在线等
时间控件的问题
java/jsp中如何实现弹出对话框选择要保存的文件的路径
请问在做网页时,如果javabean中需要有需要自行导入的包,需要把包放在哪个目录下???
还分100~~乱码问题~~谢谢那几位兄弟~~
一个关于tomcat5.0连接SQL Server2000数据库的问。。希望大家帮忙。。
我这个简单的JSP为什么产生空指针异常?
一个servlet里调用javascript的小问题,大家帮忙看看!
十万火急啊!如何编写日志文件!
热门文章
java.net.ConnectException: Connection refused: connect的问题求救.
关于session超时处理的问题
求救:关于查询,大家看看有什么问题??
java/jsp中如何实现弹出对话框选择要保存的文件的路径
form提交到另一个页面时如何设置新页面的大小
求,怎样让点击过的链接变色,跟其他为点击链接不同
用itext读取服务器pdf文件,转为普通htm显示在网页上,求例子!!!!
IText 的问题
jsp中怎么打开ppt文件,不出现保存对话框
如何实现窗口全屏显示
在JSP中select多选时提交后在下一页面中怎样得到所选的内容?
为什么使用了utf-8中文还是乱码呢?

编程社区 2008 浙ICP备09013498号
© TinyBBS.cn
编程好站连接:codeproject sf.net codeplex