第一天
实验效果:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="bean.Book" %> <% Book[] bs=new Book[5]; bs[0]=new Book(7925,"java core","经典中的糟粕","孙卫琴",85.6); bs[1]=new Book(7915,"java jsp","经典中的经典","卫孙琴",85.6); bs[2]=new Book(1925,"java oracle","糟粕中的经典","孙琴卫",85.6); bs[3]=new Book(6925,"java css","糟粕中的糟粕","琴卫孙",85.6); bs[4]=new Book(7025,"java js","经典","卫琴",85.6); %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <style tyle="text/css"> body{ text-align: center; } th{ border:1px solid black; color:white; } td{ border:1px solid black; color:green; } a{ text-decoration: none; font-size:14px; } </style> </head> <body> <table style="border-collapse: collapse;border:1px solid black; width:500px;"> <tr style="background-color:#333;"><th>编号</th><th>名称</th><th>描叙</th><th>作者</th><th>价格</th><th>操作</th></tr> <%for(int i=0;i<bs.length;i++){%> <% if(i%2==0){%> <tr style="background-color:#ccc;"> <%}else{ %> <tr style="background-color:#999;"> <%}%> <td><%=bs[i].getNo()%></td><td><%=bs[i].getName()%></td><td><a href="#" target="_BLANK"><%=bs[i].getDesc()%></a></td><td><%=bs[i].getAuthor()%></td><td><%=bs[i].getPrice()%>¥</td><td>购买</td></tr> <%} %> </table> </body> </html>
package bean; public class Book { private int no; private String name; private String desc; private String author; private double price; public int getNo() { return no; } public void setNo(int no) { this.no = no; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public Book() { super(); } public Book(int no, String name, String desc, String author, double price) { super(); this.no = no; this.name = name; this.desc = desc; this.author = author; this.price = price; } }