JSP第三次作业
1.消费总和
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page contentType="text/html"%> <%@ 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; }%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="cyan"> <p style="font-family:黑体;font-size:20"> <br>小明的菜单: <br> <% String str = "麻婆豆腐:20.6元,红烧肉:68.9"; %> <br><%=str%><br> <br> <b><i>消费总额:<%=getPriceSum(str)%></i><br> </b> <br>小亮的菜单:<br> <% str = "剁椒鱼头:62.9元,烤鸭:199元,红焖大虾:289.9元"; %> <br><%=str%><br> <br> <b><i>消费总额:<%=getPriceSum(str)%></i><br> </b> </p> </body> </h
2.时间日期
<%@ page import = "java.time.LocalDate" %> <%@ page import = "java.time.LocalTime" %> <% LocalDate date = LocalDate.now(); LocalTime time = LocalTime.now(); %> <h2> 用户在 <%= date.getYear()%>/<%= date.getMonthValue()%>/<%= date.getDayOfMonth() %><br> <%= time.getHour()%>:<%= time.getMinute()%>:<%= time.getSecond()%>访问了网页。 </h2>
<%@ page contentType="text/html" %> <%@ page pageEncoding = "utf-8" %> <HTML><body> <h1>显示访问网页的日期、时间<br>(服务器端的日期、时间)</h1> <%@ include file="time.jsp" %> </body></HTML>
3.听英语
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page contentType="text/html" %> <HTML><body bgcolor=cyan > <br>英文课文(English Text): <p style="font-family:宋体;font-size:18;color:black"> <jsp:include page="english/english.txt" /> <br>课文音频(English Audio): <jsp:include page="audio.jsp" /> </p></body></HTML> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page contentType="text/html" %> <HTML><body bgcolor = pink > <embed src = "english/english.mp3" autostart = false> 课文音频 </body></HTML> Lesson 1 A private conversation 私人谈话 ---------------------------------------- Last week I went to the theatre. I had a very good seat. The play was very interesting. I did not enjoy it. A young man and a young woman were sitting behind me. They were talking loudly. I got very angry. I could not hear the actors. I turned round.I looked at the man and the woman angrily. They did not pay any attention. In the end, I could not bear it. I turned round again. 'I can't hear a word!' I said angrily. It’s none of your business,' the young man said rudely. 'This is a private conversation!'.