从数据库中查询出来的图片按表格的…

从数据库中查询出来的图片jsp页面的代码是方法有两种,一是:jsp页面中包含有java代码

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="zhao.ai.nan.bean.newsPaper"%>
<%@ page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <title>无标题文档</title>
 </head>

 <body>
  <table border="0" align="center">
   <%
    List list = (List) request.getAttribute("list");
    int a = list.size() / 4;
    int b = list.size() % 4;
    for (int i = 0; i < a; i++) {
   %>
   <tr>
    <%
     for (int j = 0; j < 4; j++) {
       newsPaper p = (newsPaper) list.get(4 * i + j);
    %>
    <td width="220">
     <div align="center">
      <p>
       <a href="#" target='_blank'><img src="<%=p.getPhoto()%>"
         width="150" height="150" border="0" />
       </a>
      </p>
      <p style='font-size: 18px; margin-top: -15px;'>
       <a href="#" target='_blank'><font color='#05006c'><%=p.getName()%></font>
       </a>
      </p>
      <p style='font-size: 18px; LINE-HEIGHT: 1.3em; margin-top: -15px;'><%=p.getYearPrice()%>元/年
      </p>
      <p style='font-size: 18px; LINE-HEIGHT: 1.3em; margin-top: -15px;'>
       <a href="#" target='_blank'>订购</a>
      </p>
      <br />
     </div>
    </td>
    <%
     }
    %>
   </tr>
   <%
    }
    if (b != 0) {
   %>
   <tr align="left">
    <%
     for (int i = 0; i < b; i++) {
       newsPaper p = (newsPaper) list.get(4 * a + i);
    %>
    <td width="220">
     <div align="center">
      <p>
       <a href="#" target='_blank'><img src="<%=p.getPhoto()%>"
         width="150" height="150" border="0" />
       </a>
      </p>
      <p style='font-size: 18px; margin-top: -15px;'>
       <a href="#" target='_blank'><font color='#05006c'><%=p.getName()%></font>
       </a>
      </p>
      <p style='font-size: 18px; LINE-HEIGHT: 1.3em; margin-top: -15px;'><%=p.getYearPrice()%>元/年
      </p>
      <p style='font-size: 18px; LINE-HEIGHT: 1.3em; margin-top: -15px;'>
       <a href="#" target='_blank'>订购</a>
      </p>
      <br />
     </div>
    </td>
    <%
     }
    %>
   </tr>
   <%
    }
   %>

  </table>
 </body>
</html>

第二种方法是:jsp页面中不包含java代码:

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ page import="zhao.ai.nan.bean.newsPaper"%>
<%@ page import="java.util.List"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <title>无标题文档</title>
  </head>

 <body>
  <table border="0" align="center">
   <tr>
    <c:forEach var="p" items="${list}" varStatus="s">
     <td width="220">
      <div align="center">
       <p>
        <a href="#" target='_blank'><img src="${p.photo}"
          width="150" height="150" border="0" />
        </a>
       </p>
       <p style='font-size: 18px; margin-top: -15px;'>
        <a href="#" target='_blank'><font color='#05006c'>${p.name}</font>
        </a>
       </p>
       <p
        style='font-size: 18px; LINE-HEIGHT: 1.3em; margin-top: -15px;'>
        ${p.yearPrice}元/年
       </p>
       <p
        style='font-size: 18px; LINE-HEIGHT: 1.3em; margin-top: -15px;'>
        <a href="#" target='_blank'>订购</a>
       </p>
      </div>
     </td>
     <c:if test="${s.count%4 == 0}">
   </tr>
   <tr>
    </c:if>
    </c:forEach>
   </tr>
  </table>
 </body>
</html>
显示结果如图所示:

 

从数据库中查询出来的图片按表格的形式输出

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值