第二章上机指导

编写一个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>

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值