总共分为五个部分,
1.EL+JSTL前端JSP页面
2.servlet(传递数据)
3.dao(操作数据库)
4.javaBean(ORM)
5.数据库表设计
1.EL+JSTL前端JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%-- page import="com.user.bean.VimUserInformationObject" --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>用户权限管理</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<div>
<span style="color:red;font-weight:bold">
<%
if(session.getAttribute("login_user")!=null){
out.println("尊敬的"+session.getAttribute("login_user")+"<br/>");
}
%>
</span>
</div>
<div>
<a href="user/normal/servlet/loginOutUser">-注销-</a>
<a href="jsp/user/modify_password.jsp">-修改密码-</a>
</div>
<div>
<div>
<span style="color:red;font-weight:bold">
<%
if(request.getAttribute("tips")!=null){
out.println(request.getAttribute("tips")+"<br/>");
}
%>
</span>
</div>
<form method="post" action="">
<table>
<tr>
<td>序号</td>
<td>用户名</td>
<td>权限</td>
</tr>
<c:forEach items="${allUserAuthority}" var="item" varStatus="current">
<tr>
<td>${current.index}</td>
<td>${item.user_name}</td>
<td>${item.authority}</td>
</tr>
</c:forEach>
<!--
${item['user_name']}
${item['authority']}
-->
<!--
<tr>
<td>1</td>
<td>szh</td>
<td><input name="username" type="checkbox"/></td>
<td><input type="checkbox"/></td>
</tr>
-->
</table>
<!--
<input type="submit" value="确认删除" οnclick="return confirm('确认删除?');"/>
<input type="reset" value="重选">
-->
</form>
</div>
</body>
</html>
2.servlet
package com.user.manage.servlet;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.user.bean.VimUserInformationObject;
import com.user.dao.MultUserInformationDao;
public class ManagerUserAuthorityServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* Constructor of the object.
*/
public ManagerUserAuthorityServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
// 响应客户端请求的方法
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
String tips = "";
// Servlet本身并不输出响应到客户端,因此必须将请求转发到视图页面
RequestDispatcher rd;
try {
MultUserInformationDao userInformationDao = new MultUserInformationDao();
// 暂时将所有用户的数据放到登录Servlet处理,之后进行优化
List<VimUserInformationObject> allUserAuthorityObjects = userInformationDao
.query();
request.setAttribute("allUserAuthority", allUserAuthorityObjects);
//
//
// 获取转发对象
rd = request
.getRequestDispatcher("/WEB-INF/jsp/user/manager_authority.jsp");
rd.forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}