-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
王威人
committed
Nov 11, 2017
1 parent
e20cdf8
commit 034de1c
Showing
16 changed files
with
383 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> | ||
|
||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | ||
<html> | ||
<head> | ||
|
||
<title>My JSP '1.jsp' starting page</title> | ||
|
||
</head> | ||
|
||
<body> | ||
欢迎您:${user.username}<br/><br/><br/> | ||
<a href="/day19/manager/AddProduct">添加商品</a> | ||
<a href="/day19/manager/UpdateProduct">修改商品</a> | ||
<a href="/day19/manager/DeleteProduct">删除商品</a> | ||
</body> | ||
</html> |
Binary file not shown.
Binary file modified
BIN
+779 Bytes
(120%)
day19/WebRoot/WEB-INF/classes/vvr/service/SecurityService.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.8 KB
day19/WebRoot/WEB-INF/classes/vvr/web/control/AddUserRoleServlet.class
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+3.13 KB
day19/WebRoot/WEB-INF/classes/vvr/web/filter/CheckPrivilegeFilter.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> | ||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | ||
|
||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | ||
<html> | ||
<head> | ||
|
||
<title>My JSP 'addUserRoles.jsp' starting page</title> | ||
|
||
</head> | ||
|
||
<body style="text-align: center;"> | ||
<table align="center" border="1" width="60%"> | ||
<tr> | ||
<td>用户名称:</td> | ||
<td>${user.username}</td> | ||
</tr> | ||
|
||
<tr> | ||
<td>当前角色</td> | ||
<td> | ||
<c:forEach var="ur" items="${userRoles}"> | ||
${ur.name}<br/> | ||
</c:forEach> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td>系统角色</td> | ||
<td> | ||
<form action="${pageContext.request.contextPath }/AddUserRoleServlet" method="post"> | ||
<input type="hidden" name="user_id" value="${user.id }"> | ||
<c:forEach var="r" items="${roles}"> | ||
<input type="checkbox" name="role_id" value="${r.id}">${r.name}<br/> | ||
</c:forEach> | ||
<input type="submit" value="授予角色"> | ||
</form> | ||
</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> | ||
|
||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | ||
<html> | ||
<head> | ||
|
||
<title>My JSP 'login.jsp' starting page</title> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<form action="${pageContext.request.contextPath }/LoginServlet" method="post"> | ||
用户名:<input type="text" name="username"><br/> | ||
密码:<input type="text" name="password"><br/> | ||
<input type="submit" value="登陆"> | ||
</form> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package vvr.web.UI; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import vvr.domain.Privilege; | ||
import vvr.domain.Role; | ||
import vvr.domain.User; | ||
import vvr.service.SecurityService; | ||
|
||
public class AddUserRoleUIServlet extends HttpServlet { | ||
|
||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
this.doPost(request, response); | ||
} | ||
|
||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
SecurityService service = new SecurityService(); | ||
|
||
//得到用户信息 | ||
String user_id = request.getParameter("user_id"); | ||
User user = service.findUser(user_id); | ||
request.setAttribute("user", user); | ||
|
||
//得到用户当前拥有的角色 | ||
List<Role> userRoles = service.getUserRoles(user_id); | ||
request.setAttribute("userRoles", userRoles); | ||
|
||
//得到系统的所有角色 | ||
List<Role> roles = service.getAllRoles(); | ||
request.setAttribute("roles", roles); | ||
|
||
request.getRequestDispatcher("/jsp/addUserRoles.jsp").forward(request, response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package vvr.web.control; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import vvr.service.SecurityService; | ||
|
||
public class AddUserRoleServlet extends HttpServlet { | ||
|
||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
this.doPost(request, response); | ||
} | ||
|
||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
try{ | ||
|
||
SecurityService service = new SecurityService(); | ||
|
||
String user_id = request.getParameter("user_id"); | ||
String[] role_id = request.getParameterValues("role_id"); | ||
|
||
service.updateUserRoles(user_id, role_id); | ||
request.setAttribute("message", "授权成功!!!"); | ||
}catch (Exception e) { | ||
e.printStackTrace(); | ||
request.setAttribute("message", "授权失败!!!"); | ||
} | ||
request.getRequestDispatcher("/message.jsp").forward(request, response); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package vvr.web.control; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import vvr.domain.User; | ||
import vvr.service.SecurityService; | ||
|
||
public class LoginServlet extends HttpServlet { | ||
|
||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
this.doPost(request, response); | ||
} | ||
|
||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
|
||
String username = request.getParameter("username"); | ||
String password = request.getParameter("password"); | ||
|
||
SecurityService service = new SecurityService(); | ||
User user = service.login(username,password); | ||
request.getSession().setAttribute("user", user); | ||
request.getRequestDispatcher("/1.jsp").forward(request, response); | ||
} | ||
|
||
} |
Oops, something went wrong.