从数据库中查询出来的图片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>
显示结果如图所示: