<%@ 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="麻婆豆腐:18元,红烧肉:26元"; %> <br><%= str %></br> <br><b><i>消费:<%=getPriceSum(str) %></i></b></br> <br>李四的菜单</br> <% String strr="辣子鸡:50元,北京烤鸭:109元,油焖大虾:90元"; %> <br><%= strr %></br> <br><b><i>消费:<%=getPriceSum(strr) %></i></b></br> </html>
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%@ 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); %> </html>
<%@ 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="index.jsp" %> </body> </html>