使用集合提取显示书籍信息

    技术2022-05-19  26

    <%@ page language="java" contentType="text/html;charset=GBK"%><%@ page import="y2javaee.sg.ch03.TitlesBean"%><%@ page import="y2javaee.sg.ch03.BookBean" %><%@ page import="java.util.*" %><html><head><title>ebooks</title></head><body><table style="TEXT-ALIGN:center" width=50 border=0><tbody><!-- HTML美化代码 --><!-- 动态显示内容开始 --><% TitlesBean titlesBean=new TitlesBean(); //调用访问数据库方法,返回所有书籍的信息列表 List titles=titlesBean.getTitles(); BookBean currentBook; //把书籍保存在session中 session.setAttribute("titles",titles); //对书籍列表进行遍历 for(int i=0;i<titles.size();i++){  currentBook=(BookBean)titles.get(i);  if(i%3==0){  %>  <tr>  <%} %>  <td>  <table cellSpacing=0 width=180>  <tbody>  <tr>  <td valign=bottom height=30>  <a href="displayBook.jsp?isbn=<%=currentBook.getISBN() %>">  <%=subStr(currentBook.getTitle()+","+currentBook.getEditionNumber()) %>  </a>  </td>  </tr>  <tr align=middle>  <td height=120>  <a href="displayBook.jsp?isbn=<%=currentBook.getISBN() %>">  <IMG height=110 src="/store/images/<%=currentBook.getImageFile() %>" width=90></a>//图片地址,显示集合中的图片  </td>  </tr>  </tbody>  </table><br>  </td>  <%if(i%3==2){ %>  </tr>  <%}}%>   <!-- 动态显示内容结束 --> </tbody> </table> </body></html><%! //截取字符串方法 public String subStr(String str){  if(str==null||"".equals(str))   return "";  if(str.length()>20)   return str.substring(0,20)+"...";  else   return str; } %>

     


    最新回复(0)