相关知识点:
1. 需要导包的地方通过以下方式导入
<%@ page import="包路径" %>
2. 可以使用以下方式创建指定的元素
out.print("标签");
3. 使用<%= %>表达式输出内容
4. 使用<% %>小脚本编写Java语句
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="io.zhangjia.test.Book" %> <%@ page import="java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> table{ width: 40%; border: 1px #000 solid; border-spacing: 0; /*设置相邻单元格的边框间的距离为0*/ border-collapse: collapse;/*合并边框*/ } td,th{ border: 1px #000 solid; } </style> <title>Insert title here</title> </head> <body> <!-- 用表格的形式显示99乘法表 --> <table> <% for (int i = 1; i < 10; i++) { out.print("<tr>"); for (int j = 1; j <= i; j++) { out.println("<td>" + j + "*" + i + "=" + (i * j) + "\t" + "</td>"); } out.print("</tr>"); } %> </table> <!-- 用表格的形式显示Book类的对象 --> <% List<Book> books = new ArrayList<>(); books.add(new Book(1001,"西游记","吴承恩",19.9)); books.add(new Book(1002,"西游记","吴承恩",29.9)); books.add(new Book(1003,"西游记","吴承恩",39.9)); books.add(new Book(1004,"西游记","吴承恩",49.9)); %> <table> <tr> <th>编号</th> <th>书名</th> <th>作者</th> <th>价格</th> </tr> <% for(Book book: books) { out.println("<tr>"); out.println("<td>" + book.getBookId()+"</td>"); out.println("<td>" + book.getName()+"</td>"); out.println("<td>" + book.getAuthor()+"</td>"); out.println("<td>" + book.getPrice()+"</td>"); out.println("</tr>"); } %> </table> </body> </html>
请登录之后再进行评论