jsp 按列显示
<%@page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " "%>
<!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 ">
<%@page import= "beans.connDB "%>
<%
connDB conn = new connDB();
ResultSet rs1 = conn.executeQuery( "select top 4 * from zhuanti order by datetime desc ");
ResultSet rs2 = conn.executeQuery( "select top 4 * from shidian order by datetime desc ");
ResultSet rs3 = conn.executeQuery( "select top 8 * from jinghua order by datetime desc ");
%>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 "/>
<title> 无标题文档 </title>
<style type= "text/css ">
<!--
.STYLE23 {color: #9999FF;
font-size: 16px;}
.STYLE24 {color: #FF0000;
font-size: 12px;}
.STYLE28 {
font-size: 24px;
color: #FF0000;
}
.STYLE29 {
font-size: 18px;
color: #CC3399;
}
-->
</style>
</head>
<body>
<table width= "518 " height= "247 ">
<tr>
<td height= "26 " colspan= "2 ">
<span class= "STYLE28 "> 最新专题报道 </span>
</td>
</tr>
<tr>
<td width= "168 " height= "211 ">
<img src= "images/1.jpg " width= "157 " height= "209 "/>
</td>
<td width= "1 " background= "images/shuxian.bmp "> </td>
<td width= "400 ">
<table width= "344 " height= "211 ">
<tr>
<%
int ID = 0;
String biaoti = " ";
String jianjie = " ";
while (rs1.next()) {
ID = rs1.getInt(1);
biaoti = rs1.getString(2);
jianjie = rs1.getString(3);
String jiequ = jianjie.substring(0, 1);
if (ID%2 == 0) {
%>
<td valign= "top " height= "20 " class= "tableBorder_B_dashed ">
<span class= "STYLE23 "> <a href= "15.jsp " class= "v1 "> <%=biaoti%> </a> </span>
<br/>
<span class= "STYLE21 "> <%=jiequ%> ... </span>
</td>
<%} if(ID%2!=0) { %>
<td valign= "top " height= "20 " class= "tableBorder_B_dashed ">
<span class= "STYLE23 "> <a href= "15.jsp " class= "v1 "> <%=biaoti%> </a> </span>
<br/>
<span class= "STYLE21 "> <%=jiequ%> ... </span>
</td>
</tr>
<%}} %>
</table>
</td>
</tr>
</table>
<table width= "520 " height= "11 ">
<tr>
<td>
<hr width= "100% " size= "1 " color= "#CCCCCC "/>
</td>
</tr>
</table>
<table width= "522 " height= "150 ">
<tr>
<td width= "195 " valign= "top " height= "13 " scope= "row ">
<span class= "STYLE29 "> 格瑞贝斯视点 </span>
<br/>
<hr width= "100% " size= "1 " color= "#CCCCCC "/>
</td>
<td width= "315 " rowspan= "3 " scope= "row ">
<img src= "images/2.jpg " width= "314 " height= "285 "/>
</td>
</tr>
<tr>
<td height= "21 " valign= "top " scope= "row ">
<table width= "190 " height= "143 ">
<tr>
<%
int ID1 = 0;
String biaoti1 = " ";
String neirong = " ";
while (rs2.next()) {
ID1 = rs2.getInt(1);
biaoti1 = rs2.getString(2);
neirong = rs2.getString(3);
String jiequ1 = neirong.substring(0, 22);
%>
<tr>
<td height= "20 " class= "tableBorder_B_dashed ">
<div align= "left ">
<span class= "STYLE20 "> <a href= "11.jsp " class= "v2 "> <%=biaoti1%> </a> </span>
<br/>
<span class= "STYLE21 "> <%=jiequ1%> </span>
</div>
</td>
</tr>
<%} %>
</table>
</td>
</tr>
<tr>
<td align= "right ">
<span class= "STYLE30 "> <a href= "index.jsp " class= "v2 "> 更多格瑞贝斯视点 </a> </span>
</td>
</tr>
</table>
<table width= "522 ">
<tr>
<td colspan= "2 ">
<hr width= "100% " size= "1 " color= "#CCCCCC "/>
</td>
</tr>
<tr>
<td width= "237 " align= "center ">
<span class= "STYLE29 "> 财经备忘录 </span>
</td>
<td width= "273 ">
<span class= "STYLE21 "> 2007年5月1日----2007年5月30日 </span>
</td>
</tr>
<tr>
<td colspan= "2 " scope= "col ">
<hr width= "100% " size= "1 " color= "#CCCCCC "/>
</td>
</tr>
<tr>
<td colspan= "2 ">
<table width= "510 " height= "211 ">
<tr>
<%
int ID3 = 0;
String biaoti3 = " ";
String jianjie3 = " ";
while (rs3.next()) {
ID3 = rs3.getInt(1);
biaoti3 = rs3.getString(2);
jianjie3 = rs3.getString(3);
String jiequ3 = jianjie3.substring(0, 20);
if (ID3 % 2 == 0) {
%>
<td> </td>
<td valign= "top " height= "20 " class= "tableBorder_B_dashed ">
<span class= "STYLE23 "> <a href= "15.jsp " class= "v2 "> <%=biaoti3%> </a> </span>
<br/>
<span class= "STYLE21 "> <%=jiequ3%> ... </span>
</td>
<%} else { %>
<td valign= "top " height= "20 " class= "tableBorder_B_dashed ">
<span class= "STYLE23 "> <a href= "15.jsp " class= "v2 "> <%=biaoti3%> </a> </span>
<br/>
<span class= "STYLE21 "> <%=jiequ3%> ... </span>
</td>
</tr>
<%}} %>
</table>
<hr width= "100% " size= "1 " color= "#CCCCCC "/>
</td>
</tr>
</table>
<table width= "510 ">
<tr>
<td height= "70 " scope= "col ">
<img src= "images/3.jpg " width= "510 " height= "70 "/>
</td>
</tr>
</table>
<jsp:include flush= "true " page= "shishang.jsp "/>
<jsp:include flush= "true " page= "zixun.jsp "/>
<jsp:include flush= "true " page= "dow.jsp "/>
<table>
<tr>
<td align= "center ">
<img src= "images/5.jpg " width= "520 " height= "130 "/>
</td>
</tr>
</table>
</body>
</html>
上面ID%2的时候如果最后一个数据的ID是偶数可以,但是是奇数
现在我想以for循环控制ID,请问怎么控制
[解决办法]
好长的代码。看不进去。对你的问题,不清楚。
你应该讲清楚:
你的开发工具和开发环境是什么?
现在你想要干什么?
你对于你的问题做过那些?
其间遇到了什么样的问题?
[解决办法]
楼主, ResultSet rs1 = conn.executeQuery( "select top 4 * from zhuanti order by datetime desc ");
ResultSet rs2 = conn.executeQuery( "select top 4 * from shidian order by datetime desc ");
ResultSet rs3 = conn.executeQuery( "select top 8 * from jinghua order by datetime desc ");你这些从数据库读取出来,就没按列显示.其实你下面的代码不用讲了.
你想办法把这3条SQL语句 按列的形式读取出来,你的问题就解决了
[解决办法]
真象个大家庭,感觉好好的