查询分页显示,回显问题!!!!!!!!

zhengjing01 2006-03-01 03:53:31
查询分页显示后,点"下一页"等,它就变成总查询了,不知道怎么在<A Href=test.jsp?ToPage=<%= 1 %>>到第一页</A>行加查询条件代码,请各位帮哈忙!能写哈代码!谢谢
代码如下:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="org.apache.log4j.*" %>
<%@ page import="java.util.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>顾客信息报表</title>
</head>
<script language="javascript" src="CalendarPane.js"></script>
<body onload="CalendarPane.getInstance('timeTextStart');CalendarPane.getInstance('timeTextEnd')">
<CENTER>
<FONT SIZE = 5 COLOR = blue>顾客信息报表</FONT>
</CENTER>
<HR>
<h3>
<%!
static Logger log = Logger.getLogger("test.jsp");

int PageSize = 6; //record count of page
int ShowPage = 1; //show page
int RowCount = 0; //count of ResultSet
int PageCount = 0; //pages of ResultSet record

Connection conn ;
Statement stmt ;
ResultSet rs ;
String sql;

/**
* @function create a connection to database
* @return a java.sql.Connection object
*/
public Connection getConnection()throws Exception
{
log.debug("into METHOD getConnection() ...");
//Class.forName("org.gjt.mm.mysql.Driver");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/goodidea"
+"?useUnicode=true&characterEncoding=gb2312","root","");
log.debug("obtain a connection.");
log.debug("exit METHOD getConnection.");

return conn;
}
%>
<%
try
{
conn = getConnection();
stmt = conn.createStatement();
}
catch(Exception e)
{
System.out.println(e);
}

if(request.getParameter("nameSearch") != null)
{
if(request.getParameter("nameSearch").length() > 0)
{
ShowPage = 1;

sql = new String("....");
}

if(request.getParameter("citySearch").length() > 0)
{
ShowPage = 1;

sql = new String(".......");
}

String timeTextStart = request.getParameter("timeTextStart");
String timeTextEnd = request.getParameter("timeTextEnd");
if((timeTextStart.length() > 0) && (timeTextEnd.length() > 0))
{
ShowPage = 1;
sql = new String("........");
}
}
else
{
sql = new String(".......");
}

rs = stmt.executeQuery(sql);
if(rs.next())
{
rs.last();
RowCount = rs.getRow();
PageCount = ((RowCount % PageSize) == 0? (RowCount/PageSize) : (RowCount/PageSize)+1);
}
else
{
request.setAttribute("reportErr","Please Enter right information!");
%>
<jsp:forward page="reportErr.jsp"></jsp:forward>
<%
}

String ToPage = request.getParameter("ToPage");
if(ToPage != null)
{
ShowPage = Integer.parseInt(new String(ToPage.getBytes("ISO8859-1"),"UTF-8"));
if(ShowPage > PageCount)
{
ShowPage = PageCount;
}
else if(ShowPage <= 0)
{
ShowPage = 1;
}
}
rs.absolute((ShowPage - 1) * PageSize + 1);
%>
</h3>
<form name="selectform" method="post" action="test.jsp">
<H3 align="left">
请选择姓名查看方式:
</H3>
<label>
<input type="text" name="nameSearch" size="12" height="17.5">
</label>
<br>
<hr>
<h3 align="left">
请选择城市查看方式:
</h3>
<label>
<input type="text" name="citySearch" size="12" height="17.5">
</label>
<br>
<hr>
<h3 align="left">
请选择日期查看方式:
</h3>
<label>
<input type="text" name="timeTextStart" id="timeTextStart" size="12" height="17.5">
</label>到
<label>
<input type="text" name="timeTextEnd" id="timeTextEnd" size="12" height="17.5">
</label>
<br>
<hr>
<label>
<input type="submit" name="Submit" value="确定">
</label>
<label>
<input type="reset" name="canse" value="重设">
</label>
</form>
<H3 align="right">当前在第<FONT SIZE = 4 COLOR = red>
<%= ShowPage %></FONT>页, 共
<FONT SIZE = 4 COLOR = red>
<%= PageCount %></FONT>页</H3>
<hr>
<br>
<table width="739" border="1" bordercolor="RoyalBlue" align="center">
<tr>
<th width="87" scope="col" border="1" bgcolor="LightBlue">姓名</th>
<th width="87" scope="col" border="1" bgcolor="LightBlue">公司</th>
<th width="87" scope="col" border="1" bgcolor="LightBlue">城市</th>
<th width="87" scope="col" border="1" bgcolor="LightBlue">电话</th>
<th width="87" scope="col" border="1" bgcolor="LightBlue">传真</th>
<th width="87" scope="col" border="1" bgcolor="LightBlue">电邮</th>
<th width="85" scope="col" border="1" bgcolor="LightBlue">备注</th>
<th width="85" scope="col" border="1" bgcolor="LightBlue">时间</th>
</tr>
<%
for(int i = 1; i <= PageSize; i++)
{
%>
<tr>
<td><b><%= rs.getString("name")%><b></td>
<td><b><%= rs.getString("company")%><b></td>
<td><b><%= rs.getString("city")%><b></td>
<td><b><%= rs.getString("phone")%><b></td>
<td><b><%= rs.getString("fax")%><b></td>
<td><b><%= rs.getString("email")%><b></td>
<td><b><%= rs.getString("extra")%><b></td>
<td><b><%= rs.getString("addtime")%><b></td>
</tr>
<%
if(!rs.next())
break;
}
%>
</table>
<p> </p>
<TABLE>
<TR valign=baseline align=center>
<%
if(ShowPage != 1)
{
%>
<TD Width=150>
<A Href=test.jsp?ToPage=<%= 1 %>>到第一页</A> //////////
</TD>
<TD Width=150>
<A Href=test.jsp?type=ToPage=<%= ShowPage - 1 %>>到上一页</A> ////////////
</TD>
<%
}
//Current page in judgment is the last one page not is show the bottom page
//with the last one page
if(ShowPage != PageCount)
{
%>
<TD Width=150>
<A Href=test.jsp?ToPage=<%= ShowPage + 1%>>到下一页</A> ////////////
</TD>
<TD Width=150>
<A Href=test.jsp?ToPage=<%= PageCount %>>到最后一页</A> ////////////
</TD>
<%
}
%>
<TD Width=150>
<FORM action=test.jsp method=POST>
到第
<INPUT type="text" name=ToPage style="HEIGHT: 25px; WIDTH: 40px"
value=<%= ShowPage%> > 页
</FORM>
<form method=post action="reportEng.jsp" align="right">
<label>
<input type="submit" name="SubmitEng" value="English" action="reportEng.jsp">
</label>
</form>
</TD>
</TR>
</TABLE>
</body>
</html>
...全文
135 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zjh1983314 2006-03-01
把<form name="selectform" method="post" action="test.jsp">
<H3 align="left">
请选择姓名查看方式:
</H3>
<label>
<input type="text" name="nameSearch" size="12" height="17.5">
</label>
<br>
<hr>
<h3 align="left">
请选择城市查看方式:
</h3>
<label>
<input type="text" name="citySearch" size="12" height="17.5">
</label>
<br>
<hr>
<h3 align="left">
请选择日期查看方式:
</h3>
<label>
<input type="text" name="timeTextStart" id="timeTextStart" size="12" height="17.5">
</label>到
<label>
<input type="text" name="timeTextEnd" id="timeTextEnd" size="12" height="17.5">
</label>
<br>
<hr>
<label>
<input type="submit" name="Submit" value="确定">
</label>
<label>
<input type="reset" name="canse" value="重设">
</label>
</form>
里的value保持不变就可以了,可以用value="<%=request.getParamenter("")%>"
回复
mgan 2006-03-01
我帮你顶哈啊

偶也关注这个哈
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-03-01 03:53
社区公告
暂无公告