JSP第三次作业3/17
1.
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ 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>
<br>张三的菜单</br>
<%
String str="麻婆豆腐:34.3,红烧肉:40.2";
%>
<br><%= str %></br>
<br><b><i>消费:<%=getPriceSum(str) %></i></b></br>
<br>李四的菜单</br>
<%
String strr="辣子鸡:45,北京烤鸭:128,油焖大虾:188";
%>
<br><%= strr %></br>
<br><b><i>消费:<%=getPriceSum(strr) %></i></b></br>
</html>
2.
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import ="java.text.SimpleDateFormat" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<%
Date d=new Date();
SimpleDateFormat a=new SimpleDateFormat();
String now=a.format(d);
%>
<br>
<%
out.print(now);
%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<h1>显示访问网页的日期时间<br>(服务器的时间日期)</h1>
<%@ include file="time.jsp" %>
</body>
</html>
3.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body bgcolor="#faebd7">
<embed src="song/song.mp3" autostart="false">
歌曲音频
</embed>
</body>
</html>
<%@ 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>
浙公网安备 33010602011771号