编程语言
首页 > 编程语言> > 四:javaee会议管理系统实现过程之注册审批功能的代码(完整详细有注释)

四:javaee会议管理系统实现过程之注册审批功能的代码(完整详细有注释)

作者:互联网

1.只有管理员有注册审批这个权限,因此第一步是要显示待审核状态的员工

1.EmployeeDAO类

  /**
	   * 方法四:查询所有员工信息,返回到集合中
	   * @return
	   */
	  public List<Employee> selectAllEmployee(){
			 conn=ConnectionFactory.getConnection();
			 List<Employee> employeeslist=new ArrayList<Employee>();
			 Employee employee=null;	
			 try {
				PreparedStatement st=null;
				//只查询已注册且未审批 且 角色是员工的
				String sql="select * from employee where role='2' and status='0'";
		 		st = conn.prepareStatement(sql);
				ResultSet rs =st.executeQuery(sql);
				while(rs.next()){
					employee=new Employee();
					employee.setEmployeeid(rs.getInt("employeeid"));
					employee.setEmployeename(rs.getString("employeename"));
					employee.setUsername(rs.getString("username"));
					employee.setPhone(rs.getString("phone"));
					employee.setEmail(rs.getString("email"));
					employee.setStatus(rs.getString("status"));
					employee.setDepartmentid(rs.getInt("departmentid"));
					employee.setPassword(rs.getString("password"));
					employee.setRole(rs.getString("role"));
					employeeslist.add(employee);
				}
			 } catch (SQLException e) {
				    e.printStackTrace();
			}finally{
				//最后总要关闭连接
				ConnectionFactory.closeConnection();
			}
			 return employeeslist;
		 }

2.修改

新增一个

ViewAllEmployeesServlet类

package com.meeting.servlet;

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.meeting.dao.EmployeeDAO;
import com.meeting.vo.Employee;

public class ViewAllEmployeesServlet 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 {
		String code=request.getParameter("code");
		
		//新建一个DAO去调用刚才写的selectAllEmployee()方法
		EmployeeDAO dao=new EmployeeDAO();
		List<Employee> employeesList=dao.selectAllEmployee();
		//把查询得到的集合存起来叫employeesList,并且请求转发到approveaccount.jsp
		request.setAttribute("employeesList", employeesList);
		
		if(code!=null&code.equals("approve")){
			request.getRequestDispatcher("approveaccount.jsp").forward(request, response);
		}
		
	}

}

 

新增一个approveaccount.jsp

<%@ page language="java" import="java.util.*,com.meeting.vo.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
    <head>
        <title>CoolMeeting会议管理系统</title>
        <link rel="stylesheet" href="styles/common03.css"/>            
    </head>
    <body>
            <div class="page-content">
                <div class="content-nav">
                    人员管理 > 注册审批
                </div>
                <table class="listtable">
                    <caption>所有待审批注册信息:</caption>
                    <!-- 取出刚刚存起来的待审批的员工列表 -->
                    <%List<Employee> employeesList=(List<Employee>)request.getAttribute("employeesList"); %>
                    <tr class="listheader">
                        <th>姓名</th>
                        <th>账号名</th>
                        <th>联系电话</th>
                        <th>电子邮件</th>
                        <th>操作</th>
                    </tr>
                  <!--   循环迭代这个列表 -->
                    <%for(Employee e:employeesList){ %>
                    <tr>
                        <td><%=e.getEmployeename()%></td>
                        <td><%=e.getUsername()%></td>
                        <td><%=e.getPhone()%></td>
                        <td><%=e.getEmail()%></td>
                        <td>
                            <input type="button" class="clickbutton" value="通过"/>
                            <input type="button" class="clickbutton" value="不通过"/>
                        </td>
                    </tr>
                    <%}%>
                </table>
            </div>
    
        <div class="page-footer">
            <hr/>
            更多问题,欢迎联系<a href="mailto:webmaster@eeg.com">管理员</a>
            <img src="images/footer.png" alt="CoolMeeting"/>
        </div>
    </body>
</html>

 

web.xml

	<servlet>
		<servlet-name>ViewAllEmployeesServlet</servlet-name>
		<servlet-class>com.meeting.servlet.ViewAllEmployeesServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ViewAllEmployeesServlet</servlet-name>
		<url-pattern>/ViewAllEmployeesServlet</url-pattern>
	</servlet-mapping>

 

测试:

登录一个管理员的账号

可以看到,待审批的员工会显示出来

 

2.实现审批的操作:实现通过/不通过这个按钮

1.修改数据逻辑EmployeeDAO

新增一个更新用户状态的方法updateStatus()

  /**
	   * 方法五:
	   * 向表employee中插入记录,其中status和role使用默认值
	   * @param employeeid 传入的员工id
	   * @param status	传入的员工状态
	   */
	  public void updateStatus(int employeeid,String status){
		  conn=ConnectionFactory.getConnection();
		  String sql="update employee set status='"+status+"'where employeeid="+employeeid;
		  try {		
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.executeUpdate();	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			ConnectionFactory.closeConnection();
		}	  
	  }

2.写一个新的审批的servlet

ApproveServlet.java

package com.meeting.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.meeting.dao.EmployeeDAO;

public class ApproveServlet 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 {
		//得到需要审批的员工id
		int employeeid=Integer.parseInt(request.getParameter("employeeid"));
		//用oper来知道审批的操作是通过还是不通过
		String oper =request.getParameter("oper");
		EmployeeDAO dao=new EmployeeDAO();
		
		if(oper!=null&&oper.equals("yes")){
			//通过
			dao.updateStatus(employeeid,"1");
		}
		
		if(oper!=null&&oper.equals("no")){
			//不通过
			dao.updateStatus(employeeid,"2");
		}
		//请求转发跳转到
		request.getRequestDispatcher("ViewAllEmployeesServlet?code=approve").forward(request, response);
		
	}

}

 

3.修改approveaccount.jsp

修改通过与不通过的按钮

测试一下:

按通过

 

再改回0

按不通过按钮

 

 

成功!

标签:employeeid,管理系统,request,rs,javaee,注释,employee,import,servlet
来源: https://blog.csdn.net/wudingan/article/details/99712907