JSP第五周练习
1.听英语
1 <%@ page contentType="text/html"%> 2 <%@ page pageEncoding="utf-8"%> 3 <HTML> 4 <body bgcolor=pink> 5 <embed src="english/english.mp3" autostart=false> 6 课文音频 7 </embed> 8 </body> 9 </HTML>
1 <%@ page contentType="text/html"%> 2 <%@ page pageEncoding="utf-8"%> 3 <HTML> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 </head> 7 <body bgcolor=cyan> 8 <br>英文课文(English Text): 9 </br> 10 <p style="font-family:宋体;font-size:18;color:black"> 11 <jsp:include page="english/english.txt" /> 12 <br>课文音频(English Audio):</br> 13 <jsp:include page="audio.jsp" /> 14 </p> 15 </body> 16 </HTML>
2.圆和梯形的面积计算
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'Circle.jsp' starting page</title> 15 16 17 </head> 18 19 <body> 20 <% 21 String strR = request.getParameter("R"); 22 double R = Double.parseDouble(strR); 23 double area = 3.14 * R * R; 24 %> 25 圆形的面积是:<%=area %></br> 26 </body> 27 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'Ladder.jsp' starting page</title> 15 16 17 </head> 18 19 <body> 20 <% 21 String strA = request.getParameter("A"); 22 String strB = request.getParameter("B"); 23 String strC = request.getParameter("C"); 24 double a = Double.parseDouble(strA); 25 double b = Double.parseDouble(strB); 26 double c = Double.parseDouble(strC); 27 double area = (a + b) * c / 2; 28 %> 29 给到的上底为:<%=a %> 下底为:<%=b %> 高为:<%=c %> 梯形的面积是:<%=area%> 30 </body> 31 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'Main.jsp' starting page</title> 15 16 17 </head> 18 19 <body> 20 <jsp:include page="circle.jsp"> 21 <jsp:param value="5" name="R" /> 22 </jsp:include> 23 24 <jsp:include page="ladder.jsp"> 25 <jsp:param value="3" name="A"/> 26 <jsp:param value="2" name="B"/> 27 <jsp:param value="3" name="C"/> 28 </jsp:include> 29 30 </body> 31 </html>
3.表格布局和<jsp:include page=" 界面jsp"/>
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'Main.jsp' starting page</title> 15 </head> 16 17 <body> 18 <table border="5" width="1000" height="250" bgcolor="#A9E2F3"> 19 <tr> 20 <td align="center" colspan="5"><jsp:include page="Top.jsp"></jsp:include></td> 21 </tr> 22 <tr> 23 <td align="center"><jsp:include page="Left.jsp"></jsp:include></td> 24 <td align="center">Main.jsp的文件内容包含到这里</td> 25 </tr> 26 <tr> 27 <td align="center" colspan="5"><jsp:include page="End.jsp"></jsp:include></td> 28 </tr> 29 </table> 30 </body> 31 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 3 Top.jsp的文件内容包含到这里
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 3 Left.jsp的文件内容包含到这里
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 3 End.jsp的文件内容包含到这里
4.判断产生的 随机数 Math.round((Math.random() * 10)) 是奇数还是偶数,并跳转相应界面
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> 10 <base href="<%=basePath%>"> 11 12 <title>My JSP 'Even.jsp' starting page</title> 13 14 </head> 15 16 <body> 17 <table border="5" width="500" height="200" bgcolor="#0080FF"> 18 <td style="font-size: 50px">Hello,我是一个偶数!</td> 19 </table> 20 </body> 21 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> 10 <base href="<%=basePath%>"> 11 12 <title>My JSP 'Odd.jsp' starting page</title> 13 14 15 </head> 16 17 <body> 18 <table border="5" width="500" height="200" bgcolor="#FF00FF"> 19 <td style="font-size: 50px">Hello,我是一个奇数!</td> 20 </table> 21 </body> 22 </html>
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme() + "://" 5 + request.getServerName() + ":" + request.getServerPort() 6 + path + "/"; 7 %> 8 9 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 10 <html> 11 <head> 12 <base href="<%=basePath%>"> 13 14 <title>My JSP 'Math.jsp' starting page</title> 15 16 </head> 17 18 <body> 19 20 <% 21 int num = (int) Math.round((Math.random() * 10)); 22 if (num % 2 == 0) { 23 %><jsp:forward page="Even.jsp" /> 24 <% 25 } else { 26 %><jsp:forward page="Odd.jsp" /> 27 <% 28 } 29 %> 30 </body> 31 </html>