compute.html
-----------------------------------------------------------------------------------------------------------------
<html>
<head>
<title>Compute</title>
</head>
<body bgcolor="#FFFFFF">
<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>Divide</title>
</head>
<body bgcolor="#FFFFFF">
<center>
<br>
<h1>
<%
int dividend = 0;
int divisor = 0;
int result = 0;
try {
dividend = Integer.parseInt(request.getParameter("value1"));
} catch (NumberFormatException nfex) {
throw new NumberFormatException("被除數不是整數! ");
}
try {
divisor = Integer.parseInt(request.getParameter("value2"));
} catch (NumberFormatException nfex) {
throw new NumberFormatException("除數不是整數! ");
}
result = dividend / divisor;
out.println(dividend + " / " + divisor + " = " + result);
%>
</h1>
<br>
<br>
<br>
<a href="javascript: history.back();">返回</a>
</center>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------
error.jsp
-----------------------------------------------------------------------------------------------------------------
<%@ page language="java" isErrorPage="true" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>Compute error</title>
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<br><br>
<h1>錯誤資訊</h1>
<hr>
<p>
<h3><%= exception.toString() %></h3></h3>
<br><br><br>
<a href="javascript: history.back();">返回</a>
</p>
</div>
</body>
</html>
-----------------------------------------------------------------------------------------------------------------
最後運行結果顯示:
當輸入數字能夠得到正確結果
輸入其它字元時,顯示如下:
-----------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------
解決方式:
這是IE自身的問題,在
"Internet選項"--"進階"--"瀏覽"--"顯示友好HTTP"資訊(倒數第九個)
-----------------------------------------------------------------------------------------------------------------