用java,jsp和javascript写的分页及有下拉列表分页的功能

java 专栏收录该内容
19 篇文章 0 订阅
页面dubietyPosition.jsp:

[code]<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ page import="...weihu.vo.DubietyPosition" %>
<%@ page import="...weihu.dao.DubietyPositionDao" %>
<%@ page import="...weihu.util.Page" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="....util.Log" %>

<%
//从...weihu.DubietyPositionDao获得数据库的相关操作
DubietyPositionDao dpDao=null;
//显示的内容
List listDP=null;
//用于做分页
Page page1=null;
[b]try{
page1=new Page();
dpDao=page1.getDao();
String currentPageNo=request.getParameter("currentPageNo");
if(currentPageNo!=null){
page1.refresh(Integer.parseInt(currentPageNo));
}
String pageMethod=request.getParameter("pageMethod");
if(pageMethod!=null){
if(pageMethod.equals("first")){
page1.first();
}else if(pageMethod.equals("last")){
page1.last();
}
}
listDP=page1.getCurrentPage(page1.getCurrentPageNo(),page1.getPageSize());

}catch(Exception e){
Log.error(this, "dubietyPosition.jsp", e.getMessage());
}[/b]
//记录编号
int i=(page1.getCurrentPageNo()-1)*page1.getPageSize()+1;

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<style>

</style>
<link href="/include/WeiHuCSS.css" rel="stylesheet" type="text/css">

<jsp:include page="/public/_nocache.jsp" flush="true" />
<jsp:include page="/public/_head.jsp" flush="true" />
<title>可疑职位信息筛选</title>
...

<script type="text/javascript">
[b]<!-- 控制下拉列表的值 -->
function vaildate() {
//var getselect=document.thisForm2.currentPageNo.value;
// document.thisForm2.val.value=getselect;
// document.thisForm1.submit(); //这样写是提交
//下面是个连接
window.location.href = "/weihu/Server/dubietyPosition.jsp?currentPageNo=" + document.thisForm1.currentPageNo.value;
}
</script>[/b]
</head>

<body bgcolor="#E6E6E6" leftmargin="0" topmargin="0">
<table width="759" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td>
<%@include file="/weihu/inc/serve.jsp"%>
<table width="759" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="1" bgcolor="#F4F4F4"></td>
</tr>
<tr>
<td height="23" bgcolor="#E5EAEF" class="td2">
<font color="#7B7B7B"><strong>
<p style="margin-top:3px"> 您所在的位置:客户服务部 > 可疑职位信息筛选</p></strong></font>
</td>
</tr>
</table>
<form name="thisForm1" method="post" action="dubietyPosition.jsp?currentPageNo=<%=page1.getCurrentPageNo() %>" >
<table border="0" cellpadding="0" cellspacing="2" align="center"width="100%">
<tr>
<td colspan="7" class="left">同时显示职位摘要信息<input type="checkbox" οnclick="toggleAll(this);" checked="checked"/></td>
</tr>
<tr>
<th width="5%">序号</th>
<th width="20%">招聘职位</th>
<th width="35%">企业名称</th>
<th width="12%">工作地区</th>
<th width="10%">最低学历</th>
<th width="10%">工作经验</th>
<th width="8%">选择</th>
</tr>
<%if(listDP!=null){ %>
<%Iterator it=listDP.iterator();
while(it.hasNext()){
DubietyPosition dp=(DubietyPosition)it1.next();
%>
<tr class="tr<%=(i+1)%2%>">
<td><b><%=i++ %></b> </td>
<td class="left"><%=dp.getPosname() %></td>
<td class="left"><%=dp.getComname() %> </td>
<td><%=dp.getAddress() %></td>
<td><%=dp.getReqDegreeName() %></td>
<td><%if(dp.getReqWorkYear()==-100) {%>不限
<%}else{ %>
<%=dp.getReqWorkYear() %>年
<%} %>
</td>
<td>
<%if(dpDao.getMapPosState().get(new Integer(dp.getPosId())).equals(new Integer(1))){ %>
<input type="checkbox" value="<%=dp.getPosId() %>" name="posIds" disabled="disabled"/>
<%}else{ %>
<input type="checkbox" value="<%=dp.getPosId() %>" name="posIds"/>
<%} %>
</td>
</tr>
<tr class="tr<%=i%2%>" id="desc" name="desc">
<td colspan="7" class="left"><div style="padding:0 15px;">
<%=dpDao.getMap().get(new Integer(dp.getPosId())) %></div></td>
</tr>
<% }%>
<tr class="right">
<td colspan="7">
<table>
<tr>
<td>
<br/>
当前页为第 <%=page1.getCurrentPageNo() %> 页,总页数为<%=page1.getTotalPages() %>
<%if(page1.getCurrentPageNo()!=1){%> <a href="dubietyPosition.jsp?pageMethod=first"><u>第一页</u></a>
<%} if(page1.getCurrentPageNo()>1){%>
<a href="dubietyPosition.jsp?currentPageNo=<%=page1.getCurrentPageNo()-1 %>"><u>上一页</u></a>
<%} if(page1.getCurrentPageNo()<page1.getTotalPages()){%>
<a href="dubietyPosition.jsp?currentPageNo=<%=page1.getCurrentPageNo()+1 %>"><u>下一页</u></a>
<%} if(page1.getCurrentPageNo()!=page1.getTotalPages()){%>
<a href="dubietyPosition.jsp?pageMethod=last"><u>最后一页</u></a>
<%} %>

[b]<!-- 下拉列表跳转 -->
跳转到
<select name="currentPageNo" class="inputAndSelect" οnchange="vaildate()">
<%for(int k=1;k<=page1.getTotalPages();k++){
if(k==page1.getCurrentPageNo()){
%>
<option value="<%=k %>" selected="selected"><%=k %></option>
<%} else{%>
<option value="<%=k %>"><%=k %></option>
<%}} %>
</select>[/b]

</td>
</tr>
</table><br/>
选择所有<input type="checkbox" οnclick="selectAll(this)"/><input type="submit" value="屏蔽选择的职位">
</td>
</tr>
<%}else{ %>
<tr><td colspan="7" class="center">没有任何数据 </td> </tr>
<%} %>
</table>
</form>
<jsp:include page="../inc/footer.jsp" flush="true" />
</td>
</tr>
</table>
</body>
</html>

[/code]
[code]
javascript:
<script type="text/javascript">
<b><!-- 控制下拉列表的值 -->
function vaildate() {
//var getselect=document.thisForm2.currentPageNo.value;
// document.thisForm2.val.value=getselect;
// document.thisForm1.submit(); //这样写是提交
//下面是个连接
window.location.href = "/weihu/Server/dubietyPosition.jsp?currentPageNo=" + document.thisForm1.currentPageNo.value;
}
</script>[/code]
页面中对应form中的代码
[code]<select name="currentPageNo" class="inputAndSelect" οnchange="vaildate()">
<%for(int k=1;k<=page1.getTotalPages();k++){
if(k==page1.getCurrentPageNo()){
%>
<option value="<%=k %>" selected="selected"><%=k %></option>
<%} else{%>
<option value="<%=k %>"><%=k %></option>
<%}} %>
</select></b> [/code]

------------------------------------
一个工具类Page.java
[code]package com.huanglq.weihu.util;

import java.util.List;

/**
* 用于做分页
* @author huanglq
*
*/
public class Page {

//总行数
private int totalRows;

//每页显示的记录数,这里已经事先给了20条
private int pageSize=20;

//当前页
private int currentPageNo;

//总页数
private int totalPages;

//DubietyPositionDao
DubietyPositionDao dao=new DubietyPositionDao();
//构造函数
public Page(){
totalRows=dao.getTotalRows();
if(totalRows%pageSize==0){
totalPages=totalRows/pageSize;
}else{
totalPages=totalRows/pageSize+1;
}
//为防止currentPageNo出异常在这里事先给了currentPageNo=1
currentPageNo=1;
}
//获得每页的记录
public List getCurrentPage(int _currentPageNo,int _pageSize){
return dao.currentPage(_currentPageNo, _pageSize);
}

//第一页
public void first(){
currentPageNo=1;
}

//最后一页
public void last(){
currentPageNo=totalPages;
}
//防止出现大于最后一页
public void refresh(int _currentPageNo){
currentPageNo=_currentPageNo;
if(currentPageNo>totalPages)
last();
}


public int getTotalRows() {
return totalRows;
}

public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}

public int getPageSize() {
return pageSize;
}

public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}

public int getCurrentPageNo() {
return currentPageNo;
}

public void setCurrentPageNo(int currentPageNo) {
this.currentPageNo = currentPageNo;
}

public int getTotalPages() {
return totalPages;
}

public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public DubietyPositionDao getDao() {
return dao;
}
public void setDao(DubietyPositionDao dao) {
this.dao = dao;
}

}
[/code]----------------------
dao的DubietyPositionDao类的分页内容的写法1:用resultset分页

[code]//pageSize页面大小,totalRows总行数
public List getDPCurrentPage(int currentPageNo, int pageSize){
List listDP=null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
//用于计算页面的start
int total = currentPageNo * pageSize;
//每页的开始行数
int start = total - pageSize + 1;

String sql="select Top "+total+" posid,comname,posname,address_pc,reqDegreeName,reqworkyear "
+"from huanglq_query..compos_query where contains(comname,'"+COMNAMES+"') "
+"and contains(posname,'"+POSNAMES+"')";


try {
conn = DBUtil.getHuanglqQueryConn();
pstmt = conn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,//该常量指示可滚动但通常不受其他的更改影响的 ResultSet 对象的类型。
ResultSet.CONCUR_READ_ONLY);//该常量指示不可以更新的 ResultSet 对象的并发模式

rs = pstmt.executeQuery();

Log.debug(this, "getDPCurrentPage(int currentPageNo, int pageSize)", sql.toString());

if (rs.absolute(start)) {//rs指向当前页的开始行
listDP = new ArrayList();
while (rs.getRow() <= total) {
DubietyPosition dp = new DubietyPosition();
dp.setPosId(rs.getInt("posid"));
dp.setComname(rs.getString("comname"));
dp.setPosname(rs.getString("posname"));
dp.setAddress(rs.getString("address_pc"));
dp.setReqWorkYear(rs.getInt("reqworkyear"));
dp.setReqDegreeName(rs.getString("reqDegreeName"));
// 把可疑职位添加到可疑职位列表中
listDP.add(dp);

/*
* rs.nect()的作用是使rs.getRow()每次都加1,还有当页面不足要求的记录时可以跳出循环,防止null异常
*/
if (!rs.next()) {
break;
}
}
}
} catch (Exception e) {
Log.error(this, "getDPCurrentPage(int currentPageNo, int pageSize)", e.getMessage());
} finally {
DBUtil.clean(this, rs);
DBUtil.clean(this, pstmt);
DBUtil.clean(this, conn);
}
return listDP;
}

[/code]dao的DubietyPositionDao类的分页内容的写法2:用sql语句传参分页
[code]public List currentPage(int currentPageNo, int pageSize) {
List listDP = new ArrayList();// 可疑职位列表
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

int pageNo = (currentPageNo - 1) * pageSize;
int pSize = pageSize;
// 分页查询语句
String sql = "select Top "+ pSize+ " posid,comname,posname,address_pc,reqDegreeName,reqworkyear from huagnlq_query..compos_query where posid not in " + "( select Top "+ pageNo+ " posid from huanglq_query..compos_query order by inserttime desc) order by inserttime desc";

try {
conn = DBUtil.getHuanglqQueryConn();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
DubietyPosition dp = new DubietyPosition();
dp.setPosId(rs.getInt("posid"));
dp.setComname(rs.getString("comname"));
dp.setPosname(rs.getString("posname"));
dp.setAddress(rs.getString("address_pc"));
dp.setReqWorkYear(rs.getInt("reqworkyear"));
dp.setReqDegreeName(rs.getString("reqDegreeName"));
// 把可疑职位添加到可疑职位列表中
listDP.add(dp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.clean(listDP, rs);
DBUtil.clean(listDP, pstmt);
DBUtil.clean(listDP, conn);
}
return listDP;
}

[/code]DubietyPositionDao.java
[code]package com.huanglq.weihu.dao;

/**
* 这是一个装载可疑职位的类的Dao
* 这里涉及和两个数据库huanglw_query..compos_query和[huanglq].[dbo].[com_Position]
*/
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;

import com.huanglq.message.Message;
import com.huanglq.util.DBUtil;
import com.huanglq.util.DateTime;
import com.huanglq.util.Log;

public class DubietyPositionDao {

//公司名包含的字段
public static final String[] COMNAME_CONTAINS = {"娱乐","俱乐部","酒店","会所","休闲","夜总会","贵族","酒城"};

//职位包含的字段
public static final String[] POSNAME_CONTAINS = {"dj","服务员","特陪","特服生","接待","公关","陪","服务生",
"少爷","公主","伴游","特服生","私人","接待","夜总会","桑拿"};
//公司名包含的字段转换后的字段
public static String COMNAMES="";
//职位包含的字段转换后的字段
public static String POSNAMES="";

//用静态初始化块来初始化COMNAMES和POSNAMES
static {
for(int i=0;i<COMNAME_CONTAINS.length;i++){
COMNAMES=COMNAMES+COMNAME_CONTAINS[i]+" or ";
}
COMNAMES = COMNAMES.substring(0, COMNAMES.length() - 4);

for(int i=0;i<POSNAME_CONTAINS.length;i++){
POSNAMES=POSNAMES+POSNAME_CONTAINS[i]+" or ";
}
POSNAMES = POSNAMES.substring(0, POSNAMES.length() - 4);
}

//用于查询获得可疑职位总记录数的sql语句
public static final String TOTALSIZE_SQL="select count(*) from huauglq_query..compos_query where contains " +
"(comname,'"+COMNAMES+"') and contains(posname,'"+POSNAMES+"')";

// 用来存储posid和其posDescription,map(posid,posDescription)
private Map map = new HashMap();
// 用来存储posid和其posState,map(posid,posState)
private Map mapPosState = new HashMap();

// 数据库是huanglq_query..compos_query
// 获得可疑职位总记录数
public int getTotalRows() {
int totalRows = 0;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try {
conn = DBUtil.getHuanglqQueryConn();
pstmt = conn.prepareStatement(TOTALSIZE_SQL);
rs = pstmt.executeQuery();
while (rs.next()) {
totalRows = rs.getInt(1);
}
Log.debug(this, "DubietyPositionDao.getTotalRows()", TOTALSIZE_SQL);
} catch (Exception e) {
Log.error(this, "DubietyPositionDao.getTotalRows()", e.getMessage());
} finally {
DBUtil.clean(this, rs);
DBUtil.clean(this, pstmt);
DBUtil.clean(this, conn);
}
return totalRows;
}

// 数据库是huanglq_query..compos_query
// 按页查找可疑记录,用于做分页
public List currentPage(int currentPageNo, int pageSize) {
List listDP = new ArrayList();// 可疑职位列表

long startTime=new Date().getTime();

Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

int pageNo = (currentPageNo - 1) * pageSize;
int pSize = pageSize;
// 分页查询语句
String sql = "select Top "
+ pSize
+ " posid,comname,posname,address_pc,reqDegreeName,reqworkyear from huanglq_query..compos_query where posid not in "
+ "( select Top "
+ pageNo
+ " posid from huanglq_query..compos_query "
+ "where contains(comname,'"+COMNAMES+"') "
+ "and contains(posname,'"+POSNAMES+"') order by inserttime desc) "
+ "and contains(comname,'"+COMNAMES+"')"
+ " and contains(posname,'"+POSNAMES+"') order by inserttime desc";

try {
conn = DBUtil.getHuanglqQueryConn();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
DubietyPosition dp = new DubietyPosition();
dp.setPosId(rs.getInt("posid"));
dp.setComname(rs.getString("comname"));
dp.setPosname(rs.getString("posname"));
dp.setAddress(rs.getString("address_pc"));
dp.setReqWorkYear(rs.getInt("reqworkyear"));
dp.setReqDegreeName(rs.getString("reqDegreeName"));
// 把可疑职位添加到可疑职位列表中
listDP.add(dp);
}
Log.debug(this, "DubietyPositionDao.currentPage(int currentPageNo, int pageSize)", sql);
} catch (Exception e) {
Log.error(this, "DubietyPositionDao.currentPage(int currentPageNo, int pageSize)", e.getMessage());
} finally {
DBUtil.clean(listDP, rs);
DBUtil.clean(listDP, pstmt);
DBUtil.clean(listDP, conn);
}
long endTime=new Date().getTime();
System.out.println(endTime-startTime+" ***************************");
return listDP;
}

// 数据库是[huanglq].[dbo].[com_Position]
// 根据posid来修改可疑职位,把可疑记录的状态改为屏蔽,
// --PosState 0=删除,1=屏蔽,2=正常
public void modifyPosState(int posid) {
Connection conn = null;
PreparedStatement pstmt = null;
//提交后把posState改为1
String sql = "UPDATE [huanglq].[dbo].[com_Position] SET PosState =1,UpdateDate=getDate() WHERE posId=?";
try {
conn = DBUtil.getHuanglq90Conn();
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, posid);
pstmt.execute();
Log.debug(this, "DubietyPositionDao.modifyPosState(int posid)", sql);
} catch (Exception e) {
Log.error(this, "DubietyPositionDao.modifyPosState(int posid)", e.getMessage());
} finally {
DBUtil.clean(this, pstmt);
DBUtil.clean(this, conn);
}
}

// 数据库是[huanglq].[dbo].[com_Position]
// 根据posid来查找可疑职位的摘要信息,用map来存放
// 这里目的是可以减少对数据库的频繁操作,这里只操作一次
// --PosState 0=删除,1=屏蔽,2=正常
// 根据posStatus=1来找posid把checkbox的disabled="disabled"填上
// mapPosState保存mapPosState(posid,posStatus),map保存map(posid,posDescription)
//posids是一个经过转换格式的posid集合
public void getPosDescAndState(String posids) {
Connection conn = null;
Statement pstmt = null;
ResultSet rs = null;
String sql = "select posid,posDescription,posState from [huanglq].[dbo].[com_Position] WHERE posID in(";
try {
conn = DBUtil.getHuanglqConn();
pstmt = conn.createStatement();
rs = pstmt.executeQuery(sql + posids + ")");
while (rs.next()) {
Integer posId = new Integer(rs.getInt("posid"));
String posDescription = "";
try {
posDescription = rs.getString("posDescription");
} catch (Exception e) {
posDescription = "暂时还没有输入数据";
}
map.put(posId, posDescription);
mapPosState.put(posId, new Integer(rs.getInt("posState")));
}
Log.debug(this, "DubietyPositionDao.getPosDescAndState(String posids)", sql);
} catch (Exception e) {
Log.error(this, "DubietyPositionDao.getPosDescAndState(String posids)", e.getMessage());
} finally {
DBUtil.clean(this, rs);
DBUtil.clean(this, pstmt);
DBUtil.clean(this, conn);
}
}

public Map getMap() {
return map;
}

public void setMap(Map map) {
this.map = map;
}

public Map getMapPosState() {
return mapPosState;
}

public void setMapPosState(Map mapPosState) {
this.mapPosState = mapPosState;
}

//分页方法2,这个比较快
//pageSize页面大小,totalRows总行数
public List getDPCurrentPage(int currentPageNo, int pageSize){
List listDP=null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
//用于计算页面的start
int total = currentPageNo * pageSize;
//每页的开始行数
int start = total - pageSize + 1;

String sql="select Top "+total+" posid,comname,posname,address_pc,reqDegreeName,reqworkyear "
+"from huanglq_query..compos_query where contains(comname,'"+COMNAMES+"') "
+"and contains(posname,'"+POSNAMES+"')";


try {
conn = DBUtil.getHuanglqQueryConn();
pstmt = conn.prepareStatement(sql,
ResultSet.TYPE_SCROLL_INSENSITIVE,//该常量指示可滚动但通常不受其他的更改影响的 ResultSet 对象的类型。
ResultSet.CONCUR_READ_ONLY);//该常量指示不可以更新的 ResultSet 对象的并发模式

rs = pstmt.executeQuery();

Log.debug(this, "getDPCurrentPage(int currentPageNo, int pageSize)", sql.toString());

if (rs.absolute(start)) {//把rs移到当前页的开始行
listDP = new ArrayList();
while (rs.getRow() <= total) {
DubietyPosition dp = new DubietyPosition();
dp.setPosId(rs.getInt("posid"));
dp.setComname(rs.getString("comname"));
dp.setPosname(rs.getString("posname"));
dp.setAddress(rs.getString("address_pc"));
dp.setReqWorkYear(rs.getInt("reqworkyear"));
dp.setReqDegreeName(rs.getString("reqDegreeName"));
// 把可疑职位添加到可疑职位列表中
listDP.add(dp);

/*
* rs.next()的作用是使rs.getRow()每次都加1,还有当页面不足要求的记录时可以跳出循环,防止null异常
*/
if (!rs.next()) {
break;
}
}
}
} catch (Exception e) {
Log.error(this, "getDPCurrentPage(int currentPageNo, int pageSize)", e.getMessage());
} finally {
DBUtil.clean(this, rs);
DBUtil.clean(this, pstmt);
DBUtil.clean(this, conn);
}
return listDP;
}

}


[/code]/**
* DubietyPosition.java
* 这是一个装载可疑职位的类
* 用于可疑职位信息筛选
*/
[code]
package com.jobcn.weihu.vo;

public class DubietyPosition {

// 职位id
private int posId;

// 招聘职位名
private String posname;

// 公司名
private String comname;

// 地址
private String address;

// 要求学历
private String reqDegreeName;

// 工作经验
private int reqWorkYear;

public int getPosId() {
return posId;
}

public void setPosId(int posId) {
this.posId = posId;
}

public String getPosname() {
return posname;
}

public void setPosname(String posname) {
this.posname = posname;
}

public String getComname() {
return comname;
}

public void setComname(String comname) {
this.comname = comname;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getReqDegreeName() {
return reqDegreeName;
}

public void setReqDegreeName(String reqDegreeName) {
this.reqDegreeName = reqDegreeName;
}

public int getReqWorkYear() {
return reqWorkYear;
}

public void setReqWorkYear(int reqWorkYear) {
this.reqWorkYear = reqWorkYear;
}
}
[/code]
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值