?
1、頁面上顯示1~3,3個鏈接,單擊每個鏈接,能夠在另一個頁面打印該數(shù)字的平方。
代碼:
four_1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*"%>
<html>
<head>
<title>求平方</title>
</head>
<body>
<p>點(diǎn)擊計(jì)算下列數(shù)值的平方:</p >
<a href="Square.jsp?n=12">12</a><br>
<a href="Square.jsp?n=24">24</a><br>
<a href="Square.jsp?n=36">36</a><br>
</body>
</html>
Square.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>求平方</title>
</head>
<body>
<%
String str=request.getParameter("n");
int number=Integer.parseInt(str);
%>
該數(shù)的平方為:<% out.println(number*number); %>
</body>
</html>
效果:
打印數(shù)字平方
2、指定一個異常頁面,系統(tǒng)中所有的操作異常都會導(dǎo)致跳到這個頁面,調(diào)試這個頁面。
代碼:
four_2.jsp
<%@ page pageEncoding="UTF-8"%>
<html>
<head>
<title>Error Handling Example</title>
</head>
<body>
<form method="post" action="four_2_result.jsp">
被除數(shù):<input type="text" name="c1"><br/>
除數(shù):<input type="text" name="c2"><br/>
<input type="submit" name="ok" value="提交">
</form>
</body>
</html>
four_2_result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" errorPage="errorpage.jsp"%>
<html>
<head>
<title>fuwu</title>
</head>
<body>
<%
String c1=request.getParameter("c1");
String c2=request.getParameter("c2");
double num1=Double.parseDouble(c1);
double num2=Double.parseDouble(c2);
if(num2==0||c1==null||c2==null){
throw new RuntimeException("Error condition!!!");
}else{
out.println(num1/num2);
}
%>
</body>
</html>
errorpage.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="false" pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="UTF-8">
<title>Show Error Page</title>
</head>
<body>
<h1>服務(wù)器正在忙</h1>
<p>Sorry, an error occurred.</p>
</body>
</html>
效果:
異常頁面--正常輸入文章來源:http://www.zghlxwxcb.cn/news/detail-724375.html
異常頁面--異常輸入文章來源地址http://www.zghlxwxcb.cn/news/detail-724375.html
到了這里,關(guān)于Web服務(wù)端實(shí)驗(yàn)(第四章)1、2題的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!