3.17JSP作业

1.消费总和

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ 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;
}
 %>
 <HTML><body bgcolor=pink>
 <p style="font-family:黑体;font-size:20">
 <br>张三的菜单:</br>
 <% String str="麻辣豆腐:20元,红烧肉:69元";
 %>
 <br><%= str %></br>
 <br><b><i>消费总和:<%= getPriceSum(str) %></i></b></br>
 <br>李四的菜单:</br>
 <% str="剁椒鱼头:60元,烤鸭:169元,红焖大虾:280元"; %>
 <br><%= str %></br>
 <br><b><i>消费总和:<%= getPriceSum(str) %></i></b></br>
 </p>
 </body>
 </HTML>

2.日期时间

 

<%@ page contentType="text/html" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<HTML><body>
<h1>显示访问网页的日期、时间<br>(服务器端的日期、时间)</h1>
<%@ include file="time.jsp" %>
 </body>
 </HTML>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ 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>

3.听英语

<%@ page contentType="text/html;language="java" import="java.util.*" pageEncoding="utf-8"%>
<HTML><body bgcolor=pink>
<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>
<%@ page contentType="text/html;language="java" import="java.util.*" pageEncoding="utf-8"%>
<HTML><body bgcolor=pink>
<embed src="english/english.mp3"autostart=false>
课文音频
</embed>
</body>
</HTML>

 

posted @ 2021-03-25 21:25  无法显示  阅读(36)  评论(0编辑  收藏  举报