实验一 p37
<%@ page import="java.util.regex.Matcher" %> <%@ page import="java.util.regex.Pattern" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%! public double getPriceSum(String str){ Pattern pattern; Matcher matcher; String regex = "-?[0-9][0-9]*[.]?[0-9]*"; pattern = Pattern.compile(regex); matcher = pattern.matcher(str); double sum = 0; while(matcher.find()){ String string = matcher.group(); sum += Double.parseDouble(string); } return sum; } %> <html> <style> h3{ color: aquamarine; } p{ color: darkorchid; } </style> <body> <h3>张三的菜单</h3> <p><% String str = "宫保鸡丁:55.55,麻辣豆腐:33.33";%></p> <p><%=str%></p> <i>消费总和:<%=getPriceSum(str)%></i><br> <hr> <h3>李四的菜单</h3> <p><% String str1 = "酸菜鱼:33.33,水煮肉片:66.66";%></p> <p><%=str1%></p> <i>消费总和:<%=getPriceSum(str1)%></i><br> </body> </html>
实验二 p39
userTime.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <body> <a href="time.jsp">显示访问网页的日期、时间</a> </body> </html>
time.jsp
<%@ page import="java.util.Date" %> <%@ page import="java.text.SimpleDateFormat" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <style> h3{ color: darkgray; } </style> <body> <h3> 用户在 <%Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); %> <%=sdf.format(date)%> 访问了网页 </h3> </body> </html>
实验三 p39
audio.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body bgcolor="#faebd7">
<embed src="song/song.mp3" autostart="false">
歌曲音频
</embed>
</body>
</html>
listenSong.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <style> p{ font-family: "宋体"; font-size: 18px; color: darkorchid; } </style> <body bgcolor="#5f9ea0"> 音乐歌词<br> <p> <jsp:include page="song/geci.txt"></jsp:include> 歌曲音频<br> <jsp:include page="audio.jsp"></jsp:include> </p> </body> </html>