关于JSP页面 PAGE 属性跳转问题 (实例)

来源:百度知道 编辑:UC知道 时间:2024/05/05 02:52:22
我们要做除数和被除数的页面
第一个页面是 HTML 的
computer.html 代码如下:

<html>
<head>
<title>computer</title>

</head>

<body>
<div align ="center">
<form method ="post" action="divide.jsp">
<p>-----整数除法-----
<p>被除数
<input type="text" name="value1">
除数
<input type ="text" name="value2" >
</p>
<p>
<input type="submit" name="Submit" value="计算">
</p>
</form>
</div>
</body>
</html>

然后是divide.jsp页面:
<%@ page language="java" errorPage="error.jsp" contentType="text/html;charset=GBK"%>

<html>
<head>

<title&g

是不是你这里输的小数他没有转过来。出了异常。
try{
divisor=Integer.parseInt(request.getParameter("value2"));
}
catch(NumberFormatException nfex){
throw new NumberFormatException("除数不是整数!");
}

而导致divisor为0.。除0的异常没有被捕获。
你试下这里也加上try{
result=dividend/divisor;
}catch(Exception e){
e.p.....................;
}

原因在于这句:
dividend=Integer.parseInt(request.getParameter("value1"));
当你获取的值为小数的时候 Integer.parseInt()方法会抛出异常
java.lang.NumberFormatException