實(shí)驗(yàn)?zāi)繕?biāo):
掌握J(rèn)SP中指令標(biāo)識(shí)、腳本標(biāo)識(shí)、動(dòng)作標(biāo)識(shí)和注釋的使用。
實(shí)驗(yàn)內(nèi)容:
(1)編寫兩個(gè)JSP頁面,在頁面1中有一個(gè)表單,用戶通過該表單輸入用戶的姓名并提交給頁面2;
在頁面2中輸出用戶的姓名和人數(shù)。如果頁面1沒有提交姓名或者姓名含有的字符個(gè)數(shù)大于10,就跳轉(zhuǎn)到頁面1
(2)編寫4個(gè)JSP頁面。頁面1、頁面2和頁面3都含有一個(gè)導(dǎo)航條,以便用戶方便地單擊超鏈接訪問這3個(gè)頁面;頁面4為錯(cuò)誤處理頁面。要求這3個(gè)頁面通過使用include動(dòng)作標(biāo)記動(dòng)態(tài)加載導(dǎo)航條文件head.txt
實(shí)驗(yàn)代碼:
·實(shí)驗(yàn)一:
//jsp1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method=get action=jsp2.jsp>
你的名字是:
<input type=text name=username>
<input type=submit value=submit>
</form>
</body>
</html>
//jsp2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%! int count=0; %>
<%
request.setCharacterEncoding("utf-8");
String name=request.getParameter("username");
session.setAttribute("username",name);
if(name!=""&&name.length()<=10){
out.println("你好,");
out.println(name);
out.println("你是第");
out.println(++count);
out.println("個(gè)用戶");
}else{
/* 使用JavaScript跳轉(zhuǎn)(會(huì)有提示框)
<!-- <script type="text/javascript">
window.location="jsp1.jsp";
alert(window.location.href);
</script> --> */
/* 使用response對象跳轉(zhuǎn) */
response.sendRedirect("jsp1.jsp");
}%>
</body>
</html>
關(guān)于jsp頁面跳轉(zhuǎn)的博客(非本人)

表單輸入

第一個(gè)用戶訪問

第二個(gè)用戶訪問

使用JavaScript跳轉(zhuǎn)(會(huì)有提示框)
·實(shí)驗(yàn)二:
//head.txt
<table cellSpacing="1" cellPadding="1" width="60%" align="center" border="0" >
<tr valign="bottom">
<td><A href="jsp01.jsp"><font size=3>jsp01.jsp頁面</font></A></td>
<td><A href="jsp02.jsp"><font size=3>jsp02.jsp頁面</font></A></td>
<td><A href="jsp03.jsp"><font size=3>jsp03.jsp頁面</font></A></td>
</tr>
</Font>
</table>
//jsp01.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<jsp:include page="head.txt"/>
</head>
<body>
<br/>
<font size=5 color=red>
This is jsp01.jsp
</font>
</body>
</html>
//jsp02.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsp02</title>
<jsp:include page="head.txt"/>
</head>
<body>
<br/>
<font size=5 color=red>
This is jsp02.jsp
</font>
</body>
</html>
//jsp03.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsp03</title>
<jsp:include page="head.txt"/>
</head>
<body>
<br/>
<font size=5 color=red>
This is jsp03.jsp
</font>
</body>
</html>
//jsp04.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jsp04</title>
<jsp:include page="head.txt"/>
</head>
<body>
<br/>
<font size=5 color=red>
This is the error page
</font>
</body>
</html>

屏幕快照 2018-10-17 下午3.20.04.png

屏幕快照 2018-10-17 下午3.20.11.png

屏幕快照 2018-10-17 下午3.20.16.png

屏幕快照 2018-10-17 下午3.19.57.png