显示页query.jsp
<%@ page language="java" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
//查询
function getInfoByKey(){
//查询索引
var items = document.getElementById("searchItem");
var act = items.options[items.selectedIndex].text;
if(act=="产品名称"){
act = "produceName";
}else if(act=="证书编号"){
act = "producingCertificateNumber";
}else if(act=="生产商"){
act = "manufactureName";
}else if(act=="检查机构"){
act="certificationInstitution";
}
//查询关键字
var keywords = document.getElementById("key").value;
//是否精确查询
var itemsQuery = document.getElementById("queryMode");
var queryMode = itemsQuery.options[itemsQuery.selectedIndex].text;
if(queryMode == "模糊"){
queryMode = "like";
}else if(queryMode == "精确"){
queryMode = "is";
}
//每页显示的条数
var itemsCount = document.getElementById("perPage");
var perPage = itemsCount.options[itemsCount.selectedIndex].text;
//iframe
var ifrm = document.getElementById('detailIframe');
//全部查询条件
if(keywords == null || keywords == ""){
ifrm.src = "server.jsp?perPage="+perPage;
}else{
ifrm.src = "server.jsp?act="+act+"&keywords="+keywords+"&queryMode="+queryMode+"&perPage="+perPage;
}
}
</script>
<base href="<%=basePath%>">
<title>My JSP starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body><br><br><hr><br><br>
<div align="center" id="mainDiv">
<table border="1" width="800" id="mainTable">
<tr>
<td colspan="2">无公害农产品查询
<div align="right">
<input type="button" value="返回主页">
<input type="button" value="返回上一界面">
<input type="button" value="历史查询记录">
</div>
</td>
</tr>
<tr>
<td width="200">
<table>
<tr><td align="center">检索导航</td></tr>
<tr></tr><tr></tr><tr></tr>
<tr>
<td align="center">请选择检索范围:
<select>
<option>种植业</option>
</select>
</td>
</tr>
<tr><td align="left"><input type="checkbox">粮油类</td></tr>
<tr><td align="left"><input type="checkbox">蔬菜类</td></tr>
<tr><td align="left"><input type="checkbox">设施蔬菜类</td></tr>
<tr><td align="left"><input type="checkbox">果品类</td></tr>
<tr><td align="left"><input type="checkbox">茶叶类</td></tr>
<tr><td align="left"><input type="checkbox">其它作物类</td></tr>
<tr><td align="left"></td></tr>
<tr><td align="center"><input type="button" value="分类检索"></td></tr>
</table>
</td>
<td rowspan="2" valign="top">
<form name="search" method="post">
<table width="600" id="searchTable">
<tr><td>检索项</td><td>匹配</td><td colspan="4">检索词</td></tr>
<tr>
<td>
<select id="searchItem">
<option>产品名称</option><option>证书编号</option><option>生产商</option><option>检查机构</option>
</select>
</td>
<td>
<select id="queryMode">
<option>模糊</option>
<option>精确</option>
</select>
</td>
<td colspan="3"><input id="key" type="text" size="60"></td>
<td colspan="2" align="left"><input type="button" value="检索" οnclick="getInfoByKey()"></td>
</tr>
<tr>
<td>排序
<select>
<option>按照产品分类</option>
<option>按照产品名称</option>
<option>按照标准名称</option>
</select>
</td>
<td>每页
<select id="perPage">
<option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option>
</select>
</td>
</tr>
<tr>
<td colspan="7">
<iframe id="detailIframe" width="0" height="0"></iframe>
<div id="detailDiv"></div>
</td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td>相似检索词</td>
</tr>
</table>
</div>
</body>
</html>
处理页:server.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="com.pickedpoint.SAFAS.mobilecatch.server.hibernate.website.DAO.TPrUserproducingcertificateOperate;"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%
//查询索引
String act=request.getParameter("act");
System.out.println("act:"+act);
//查询关键字
String keywords=request.getParameter("keywords");
System.out.println("keywords:"+keywords);
//查询模式
String queryMode=request.getParameter("queryMode");
System.out.println("queryMode:"+queryMode);
//每页显示条数
String perPage=request.getParameter("perPage");
System.out.println("perPage:"+perPage);
//查询类
TPrUserproducingcertificateOperate operate = new TPrUserproducingcertificateOperate();
//查询结果
List list = null;
//查询
if(keywords==null || keywords==""){//如果没有输入关键字,则为全部查询
list = operate.Query();
}else{//条件匹配查询
if(queryMode.equals("like")){
String query = act + " like '%" + keywords + "%'";
list = operate.QueryUserproducing(query);
}else if(queryMode.equals("is")){
String query = act + " = '" + keywords + "'";
list = operate.QueryUserproducing(query);
}
}
//总共查出多少条
int count = list.size();
request.setAttribute("list", list);
//总共多少页
int countPageTmp = count % Integer.parseInt(perPage);
int countPage = 1;
if(countPageTmp != 0 || count == 0){
countPage = count / Integer.parseInt(perPage) + 1;
}else{
countPage = count / Integer.parseInt(perPage);
}
%>
<%
//当前是第几页
String currentPage = request.getParameter("currentPage");
if(currentPage == null || currentPage == "") currentPage = "1";
//当前从第几条开始显示
int showPage = (Integer.parseInt(currentPage)-1) * Integer.parseInt(perPage);
String showCount = String.valueOf(showPage);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
//判断翻页按钮的可用性
function inint(){
alert(document.getElementById("forBtn").disabled);
document.getElementById("forBtn").disabled = true;
alert(document.getElementById("forBtn").disabled);
if(document.getElementById("countDiv").innerHTML < 2){
document.getElementById("nextBtn").disabled = true;
}
}
//查询索引
var items = window.parent.document.getElementById("searchItem");
var act = items.options[items.selectedIndex].text;
if(act=="产品名称"){
act = "produceName";
}else if(act=="证书编号"){
act = "producingCertificateNumber";
}else if(act=="生产商"){
act = "manufactureName";
}else if(act=="检查机构"){
act="certificationInstitution";
}
//查询关键字
var keywords = window.parent.document.getElementById("key").value;
//是否精确查询
var itemsQuery = window.parent.document.getElementById("queryMode");
var queryMode = itemsQuery.options[itemsQuery.selectedIndex].text;
if(queryMode == "模糊"){
queryMode = "like";
}else if(queryMode == "精确"){
queryMode = "is";
}
//每页显示的条数
var itemsCount = window.parent.document.getElementById("perPage");
var perPage = itemsCount.options[itemsCount.selectedIndex].text;
//向上翻页
function pageUp(){
//总页数
var countPage = document.getElementById("countDiv").innerHTML;
//翻页后的页数
var currentPage = document.getElementById("currentDiv").innerHTML-1;
document.search.action = "server.jsp?act="+act+"&keywords="+keywords+"&queryMode="+queryMode+"&perPage="+perPage+"¤tPage="+currentPage;
document.search.submit();
}
//向下翻页
function pageDown(){
//总页数
var countPage = document.getElementById("countDiv").innerHTML;
//翻页后的页数
var currentPage = document.getElementById("currentDiv").innerHTML+1;
document.search.action = "server.jsp?act="+act+"&keywords="+keywords+"&queryMode="+queryMode+"&perPage="+perPage+"¤tPage="+currentPage;
document.search.submit();
}
</script>
</head>
<body οnlοad="">
<div id="detailDiv">
<table width="550" border="1">
<tr><td>省名</td><td>市县名</td><td>乡镇名</td><td>证书编号</td><td>产品编号</td><td>生产单位</td><td>查看</td></tr>
<logic:iterate offset="<%=showCount %>" length="<%=perPage%>" id="showList" name="list" type="com.pickedpoint.SAFAS.mobilecatch.server.hibernate.model.TPrUserproducingcertificate">
<tr>
<td><bean:write name="showList" property="producingProvince"/></td>
<td><bean:write name="showList" property="producingCity"/></td>
<td><bean:write name="showList" property="producingTown"/></td>
<td><bean:write name="showList" property="producingCertificateNumber"/></td>
<td><bean:write name="showList" property="userProducingCertificateId"/></td>
<td><bean:write name="showList" property="manufactureName"/></td>
<td> <a href="detail.jsp?id=<%=showList.getUserProducingCertificateId()%>">详细</a> </td>
</tr>
</logic:iterate>
</table>
<table width="550">
<tr>
<td colspan="7" align="right">
<div style='float="right"'>
<div style='float="left"'>页:</div>
<div id="currentDiv" style='float="left"'><%=currentPage%></div>
<div style='float="left"'>/</div>
<div style='float="left"' id="countDiv"><%=countPage %></div>
<div style='float="left"'> 共<%=count %>条</div>
<div id="pageControl" style='float="left"'><input id="forBtn" type="button" value="上一页" οnclick="pageUp()"><input id="nextBtn" type="button" value="下一页" οnclick="pageDown()"></div>
</div>
</td>
</tr>
</table>
</div>
<script>
<!--
inint();
window.parent.document.all['detailDiv'].innerHTML=document.all['detailDiv'].innerHTML;
-->
</script>
</body>
</html>
注意script的位置