从数据库中查询出来的图片按表格的…
2014-03-24 13:22
204 查看
从数据库中查询出来的图片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>
显示结果如图所示:
<%@ 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>
显示结果如图所示:
相关文章推荐
- com.microsoft.sqlserver.jdbc.SQL…
- DB2和Oracle查看系统的sequence
- How to Avoid SQL Injection Vulnerabilities
- Oracle学习(一)
- MySQL数据库中文乱码的问题
- win764位安装mysql-5.6
- sql查询将列里面的值替换为别的值但是实际值不变
- win764位安装mysql-5.6
- sql中内联 和外联 区别
- 连接Oracle数据库的Hibernate配置…
- sql中内联 和外联 区别
- 连接Oracle数据库的Hibernate配置…
- 解析oracle的rownum
- plsql 分页
- 解析oracle的rownum
- plsql 分页
- JDBC连接MySQL数据库及示例
- PLSQL导入/导出数据方法
- PLSQL导入/导出数据方法
- JDBC连接MySQL数据库及示例