一、实验目的
|
二、实验项目内容(实验题目) 1、编写jsp文件,熟悉jsp动作标记include,参考课本上机实验2.8.3 2、编写jsp文件,熟悉jsp动作标记forward,参考课本上机实验2.8.4 |
三、源程序(实验步骤/实验过程/算法) (1) NewFile.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 bgcolor =cyan> <%@ page import ="java.util.regex.Pattern" %> <%@ page import ="java.util.regex.Matcher" %> <%! public double getPriceSum(String input){ Pattern pattern; Matcher matcher; String regex= "- ?[0-9][0-9] * [.]?[0-9]*" ; pattern= Pattern.compile(regex); matcher = pattern.matcher(input) ; double sum= 0; while(matcher.find()){ String str = matcher.group(); sum += Double. parseDouble(str); } return sum; } %> <p style= "font - family:黑体;font - size:20"> <br>张三的菜単:</br> <% String str= "麻辣豆腐:20.6元,红烧肉:68.9元"; %> <br><%=str%></br> <br><b><i>消費息和:<%=getPriceSum(str) %></i></b></br> <br>李四的菜单: </br> <% str= "剁椒鱼头:62.9元,烤鸭:199元,红焖大虾:289.9元";%> <br> <%=str%> </br > <br><b><i>消費息和:<%=getPriceSum(str) %></i></b></br> <br>李四的菜单: </br> </p > </body> </html> (2) listenEnglish.jsp <%@ page language="java" contentType="text/html;utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> </head> <body bgcolor =cyan> <br> 英文课本(English Text): </br > <p style= "font-family:宋体;font - size:18;color:black"> <jsp:include page = "english/english.txt"/> <br> 课本音频(English Audio): </br > <jsp:include page="audio.jsp"/> </p> </body> </html> audio.jsp <%@ page language="java" contentType="text/html;utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Insert title here</title> </head> <body bgcolor =pink> <embed src="english/english.mp3" autostart = false> 课本音频 </embed> </body> </html> 四、实验分析、总结 (1) (2) (空间不够,可加附页) |