编写一个JSP程序实现手表的功能,显示当前时间(时:分:秒),并不停地自动刷新时间。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>实时刷新当前时间</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="refresh" content="1">
</head>
<body>
<%
Date time = new Date();
int hour = time.getHours();
int min=time.getMinutes();
int second = time.getSeconds();
%>
<h2>当前时间是: <%=hour%>:<%=min%>:<%=second%></h2>
</body>
</html>
编写一个JAVA类和一个JSP页面,把下列信息封装到3个Student对象里,再把每个对象放到一个ArrayList对象里,再利用ArrayList对象在JSP页面的表格中显示所下表所示的信息
JSP页面
<%@ page language="java" import="java.util.*,com.ch2.Student" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>学生信息显示</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<table border="1" width="80%" align="center">
<tr>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>班级</th>
<th>成绩</th>
</tr>
<%
Student stu1= new Student("001","李白","男","01",723.0);
Student stu2= new Student("002","孟浩然","男","02",689.0);
Student stu3= new Student("003","杨玉环","女","03",600.0);
ArrayList arr = new ArrayList();
arr.add(stu1);
arr.add(stu2);
arr.add(stu3);
for(int i=0;i<arr.size();i++){
Student stu =(Student)arr.get(i);
%>
<tr>
<td><%=stu.getSno()%></td>
<td><%=stu.getSname()%></td>
<td><%=stu.getSex()%></td>
<td><%=stu.getClasses()%></td>
<td><%=stu.getScore()%></td>
</tr>
<%} %>
</table>
</body>
</html>
java
package ch2;
public class Student {
private String id;
private String name;
private String sex;
private String classes;
private double grade;
public Student()
{
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getClasses() {
return classes;
}
public void setClasses(String classes) {
this.classes = classes;
}
public double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}
}
编写一个JSP程序,使用JSP Scriptlet显示网页上的不同颜色的颜色条,暂显示如下颜色的颜色条:绿色、蓝绿色、黑色、红色、黄色及粉红。(对应的颜色为:Green、Cyan、Black、Red、Yellow、Pink)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>彩色颜色条纹显示</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<%
String[] colors={"Green","Cyan","Black","Red","Yellow","Pink"};
for(int i=0;i<colors.length;i++)
{
%>
<hr color="<%=colors[i] %>" ></hr>
<% }%>
</body>
</html>