package com.teachingaward.util;
import java.util.List;
/**
* 分页功能接口
* @author feng@lu
* 2014-8-5 下午8:08:33
*/
public interface SplitPage {
//获取总记录数
int getTotalCount();
//获取总页数
int getTotalPage();
//按页获取记录
List queryPerPage(int page);
//设置每页显示的记录数
void setCountPerPage(int countPerPage);
}
============================
package com.teachingaward.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.teachingaward.vo.SystemUser;
/**
* 实现分页接口的类
* @author feng@lu
* 2014-8-5 下午8:15:32
*/
public class SplitPageTmp implements SplitPage {
private int countPerPage = 5;//每页显示的元素个数
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
@Override
//获取总记录数
public int getTotalCount() {
int totalCount = 0;//设置总记录数默认值为0
try {
conn = DB.getConnection();
String sql = "select count(*) from system_users where authority=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "申报员");
rs = pstmt.executeQuery();
if(rs.next()){
totalCount = rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DB.free(rs, pstmt, conn);
}
return totalCount;
}
@Override
//获取总页数
public int getTotalPage() {
int totalCount = this.getTotalCount();
int totalPage = 0;
if(totalCount % countPerPage == 0){
totalPage = totalCount / countPerPage;
}else{
totalPage = totalCount / countPerPage + 1;
}
return totalPage;
}
@Override
//按页获取记录
public List queryPerPage(int page) {
List list = new ArrayList();
int startRow = (page - 1) * countPerPage;//定义开始页起始元素
try {
conn = DB.getConnection();
String sql = "select * from system_users where authority=? limit ?, ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, "申报员");
pstmt.setInt(2, startRow);
pstmt.setInt(3, countPerPage);
rs = pstmt.executeQuery();
while(rs.next()){
SystemUser user = new SystemUser();
user.setUsername(rs.getString("username"));
user.setName(rs.getString("name"));
list.add(user);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DB.free(rs, pstmt, conn);
}
return list;
}
@Override
//设置每页显示的记录数
public void setCountPerPage(int countPerPage) {
this.countPerPage = countPerPage;
}
}
=======================================
package com.teachingaward.util;
/**
* 返回分页查询的dao-SplitPageTmp对象
* @author feng@lu
* 2014-8-5 下午8:33:20
*/
public class UserDao {
public static SplitPage getUserTMP(){
return new SplitPageTmp();
}
}
====================================
package com.teachingaward.supervise.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.teachingaward.util.UserDao;
import com.teachingaward.vo.SystemUser;
public class UserManagerServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//这种编码
request.setCharacterEncoding("utf-8");
SystemUser user = new SystemUser();
//获取action参数
// String action = request.getParameter("action");
// if("showAllUser".equals(action)){
int page = 1;
String p = request.getParameter("page");
if(p!=null){
page = Integer.parseInt(p);
}
int totalCount = UserDao.getUserTMP().getTotalCount();
int totalPage = UserDao.getUserTMP().getTotalPage();
List list = UserDao.getUserTMP().queryPerPage(page);
request.setAttribute("totalCount", new Integer(totalCount));
request.setAttribute("totalPage", new Integer(totalPage));
request.setAttribute("page", new Integer(page));
request.setAttribute("allList", list);
//转发
request.getRequestDispatcher("/WEB-INF/pages/supervise/Supervisory_Personnel.jsp").forward(request, response);
// }
}
}
=================================================
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
吉首大学本科教学工作奖励统计分析系统监督
吉首大学本科教学工作奖励统计分析系统-监督
欢迎您:${sessionScope.declareName }
页面左部导航
<%
int totalCount = (Integer)request.getAttribute("totalCount");
int totalPage = (Integer)request.getAttribute("totalPage");
int p = (Integer)request.getAttribute("page");
/* pageContext.setAttribute("p", p); */
%>
申报总人数:
${requestScope.totalCount } 当前页:
${page }<%-- <%=p %>${p } --%>
总页数:
${totalPage }
申报人员列表
序号 |
工号 |
姓名 |
身份 |
操作 |
${ status.index + 1} |
${u.username } |
${u.name } |
申报员 |
审核 |
<%if(p==1){ %>
首页
下一页
末页
<%}if(p==totalPage){ %>
上一页
首页
<%}if(p!=1 && p!=totalPage){ %>
首页
上一页
下一页
末页
<%} %>
=================================
package com.teachingaward.controller;
/**
* 登录servlet控制器
* 2014/7/24
*/
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.teachingaward.service.impl.LoginService;
import com.teachingaward.service.impl.SearchAllUserService;
import com.teachingaward.supervise.service.impl.FindAllDeclareUsers;
import com.teachingaward.vo.SystemUser;
public class ServletLogin extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//设置编码
request.setCharacterEncoding("utf-8");
//获取登录用户的验证信息
String name = request.getParameter("username");
String pwd = request.getParameter("password");
String authority = request.getParameter("authority");
//调用service层
LoginService loginService = new LoginService();
boolean flag = false;
try {
flag = loginService.login(name, pwd, authority);
} catch (SQLException e) {
e.printStackTrace();
}
//跳转到不同的视图
if(flag){ //根据权限跳转到不同的视图
if("管理员".equals(authority)){ //管理员视图
// System.out.println("管理员登录");
//把申报员姓名存入session中,以便获取
request.getSession().setAttribute("declareName", name);
//①:查询所有的用户,存入list中
SearchAllUserService allUserService = new SearchAllUserService();
List list = null;
try {
list = allUserService.searchAllUsers(name);
} catch (SQLException e) {
e.printStackTrace();
}
//②:必须把数据库中的所有用户查询出来,request.setAttribute("list", list);
request.setAttribute("userList", list);
//③:请求转发到显示所有用户的页面,取出request域中的list属性
request.getRequestDispatcher("/WEB-INF/pages/system_management/System_Administrator.jsp").forward(request, response);
}else if("申报员".equals(authority)){ //申报员视图
// System.out.println("申报员登录");
//把申报员姓名存入session中,以便获取
request.getSession().setAttribute("declareName", name);
//转发到申报首页
request.getRequestDispatcher("/WEB-INF/pages/declare/Dteacher_Award.jsp").forward(request, response);
}else if("规则员".equals(authority)){ //规则制定员视图
// System.out.println("规则制定员登录");
//把申报员姓名存入session中,以便获取
request.getSession().setAttribute("declareName", name);
//转发到规则制定首页
request.getRequestDispatcher("/WEB-INF/pages/rule/Rteacher_Award.jsp").forward(request, response);
}else if("监督员".equals(authority)){ //监督员视图
System.out.println("监督员登录");
//把申报员姓名存入session中,以便获取
request.getSession().setAttribute("declareName", name);
//①:查询所有的用户,存入list中
FindAllDeclareUsers allUserService = new FindAllDeclareUsers();
List list = null;
list = allUserService.findAllUsers(name, authority);
//②:必须把数据库中的所有用户查询出来,request.setAttribute("list", list);
if(list!=null){
request.setAttribute("allList", list);
}
//③:请求转发到显示所有用户的页面,取出request域中的list属性
//转发到Servlet
request.getRequestDispatcher("/servlet/UserManagerServlet").forward(request, response);
//转发到监督首页
// request.getRequestDispatcher("/WEB-INF/pages/supervise/Supervisory_Personnel.jsp").forward(request, response);
}else{//"-1".equals(authority)----没必要判断,因为在数据查找中因为验证了authority等于"-1"
//这里面的内容永远得不到执行
}
}else{ //登录失败回到登录页面
response.sendRedirect("/"+ request.getContextPath() +"/login.jsp");
}
}
}
======================================================
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
吉首大学本科教学工作奖励信息化系统