Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BudgetManagementSystem
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王利雷
BudgetManagementSystem
Commits
9f52ee39
Commit
9f52ee39
authored
May 11, 2019
by
shj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
登录拦截完成,用户未登录时只能查看登录页面,登录之后自动跳转到首页,即创建预算页面,首页增加退出登录按钮
parent
cd8efb02
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
320 additions
and
22 deletions
+320
-22
IUserDao.java
src/main/java/dao/IUserDao.java
+2
-0
IUserDao.xml
src/main/java/dao/IUserDao.xml
+5
-0
BudgetHandler.java
src/main/java/handlers/BudgetHandler.java
+4
-7
LoginHandler.java
src/main/java/handlers/LoginHandler.java
+52
-2
LoginInterceptor.java
src/main/java/interceptors/LoginInterceptor.java
+8
-7
IUserBudgetService.java
src/main/java/service/IUserBudgetService.java
+7
-0
IUserService.java
src/main/java/service/IUserService.java
+4
-0
UserBudgetService.java
src/main/java/service/impl/UserBudgetService.java
+6
-0
UserService.java
src/main/java/service/impl/UserService.java
+14
-1
spring-mvc.xml
src/main/resources/spring-mvc.xml
+1
-0
index.jsp
src/main/webapp/WEB-INF/index.jsp
+198
-0
web.xml
src/main/webapp/WEB-INF/web.xml
+4
-5
index.jsp
src/main/webapp/index.jsp
+1
-0
login.jsp
src/main/webapp/login.jsp
+14
-0
No files found.
src/main/java/dao/IUserDao.java
View file @
9f52ee39
...
...
@@ -4,4 +4,6 @@ import beans.User;
public
interface
IUserDao
{
User
selectUserByName
(
String
name
);
void
insertUser
(
User
user
);
}
src/main/java/dao/IUserDao.xml
View file @
9f52ee39
...
...
@@ -5,4 +5,8 @@
<select
id=
"selectUserByName"
resultType=
"beans.User"
>
select * from user where name=#{name}
</select>
<insert
id=
"insertUser"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into user(name,password) values(#{name},#{password})
</insert>
</mapper>
\ No newline at end of file
src/main/java/handlers/BudgetHandler.java
View file @
9f52ee39
...
...
@@ -110,12 +110,12 @@ public class BudgetHandler {
String
filePath
=
getFilePath
(
Long
.
toString
(
sessionID
));
serializeBudget
(
budget
,
filePath
);
response
.
setHeader
(
"content-disposition"
,
"attachment;filename=Budget"
+
sessionID
+
".csv"
);
//
response.setHeader("content-disposition", "attachment;filename=Budget" + sessionID + ".csv");
System
.
out
.
println
(
"ContextPath: "
+
request
.
getContextPath
());
System
.
out
.
println
(
session
.
getServletContext
().
getRealPath
(
""
));
budgetToOutputStream
(
budget
,
response
.
getOutputStream
());
//
budgetToOutputStream(budget, response.getOutputStream());
}
catch
(
IO
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -492,11 +492,8 @@ public class BudgetHandler {
/**
* 修改预算中的劳务费、规则中的劳务费
*
* @param mode
* @param id
* @param name
* @param price
* @param consultation
* @param nums
* @param curd
* @param request
...
...
src/main/java/handlers/LoginHandler.java
View file @
9f52ee39
...
...
@@ -3,12 +3,16 @@ package handlers;
import
beans.User
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.servlet.ModelAndView
;
import
service.IUserService
;
import
javax.jws.soap.SOAPBinding
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
@Controller
public
class
LoginHandler
{
...
...
@@ -17,17 +21,63 @@ public class LoginHandler {
return
"login.jsp"
;
}
@RequestMapping
(
"/"
)
public
String
indexPage
(){
System
.
out
.
println
(
"show index"
);
return
"index.jsp"
;
}
@Autowired
private
IUserService
userService
;
@RequestMapping
(
"/Login"
)
public
void
loginAction
(
User
user
,
HttpServletRequest
request
,
HttpServletResponse
response
){
public
void
loginAction
(
User
user
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
if
(
userService
.
checkUser
(
user
))
{
response
.
addCookie
(
new
Cookie
(
"userid"
,
user
.
getId
().
toString
()));
response
.
addCookie
(
new
Cookie
(
"username"
,
user
.
getName
()));
//response.sendRedirect(request.getContextPath()+"/");
System
.
out
.
println
(
"back to index page"
);
}
else
{
;
response
.
sendError
(
444
,
"no such user"
)
;
}
}
/**
* 注册用户
* @param user
* @param request
* @param response
* @throws IOException
*/
@RequestMapping
(
"/Register"
)
public
void
registerAction
(
User
user
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
if
(
userService
.
existUser
(
user
)){
response
.
sendError
(
444
,
"username already exists."
);
return
;
}
userService
.
addUser
(
user
);
response
.
addCookie
(
new
Cookie
(
"userid"
,
user
.
getId
().
toString
()));
response
.
addCookie
(
new
Cookie
(
"username"
,
user
.
getName
()));
System
.
out
.
println
(
"register done"
);
}
/**
* 退出登录
* @param request
* @param response
* @throws IOException
*/
@RequestMapping
(
"/Logout"
)
public
void
logoutAction
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
Cookie
cookie
=
new
Cookie
(
"userid"
,
null
);
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
request
.
getContextPath
());
response
.
addCookie
(
cookie
);
cookie
=
new
Cookie
(
"username"
,
null
);
cookie
.
setMaxAge
(
0
);
cookie
.
setPath
(
request
.
getContextPath
());
response
.
addCookie
(
cookie
);
response
.
sendRedirect
(
request
.
getContextPath
());
}
}
src/main/java/interceptors/LoginInterceptor.java
View file @
9f52ee39
...
...
@@ -11,19 +11,20 @@ public class LoginInterceptor implements HandlerInterceptor {
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
System
.
out
.
println
(
"preHandle"
);
if
(!
checkCookie
(
request
.
getCookies
(),
"userid"
))
{
request
.
getRequestDispatcher
(
"/LoginPage"
).
forward
(
request
,
response
);
if
(!
checkCookie
(
request
.
getCookies
(),
"userid"
))
{
request
.
getRequestDispatcher
(
"/LoginPage"
).
forward
(
request
,
response
);
//response.sendRedirect(request.getContextPath()+"/login.jsp"
);
return
false
;
}
return
true
;
}
private
boolean
checkCookie
(
Cookie
[]
cookies
,
String
name
)
{
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
name
))
return
true
;
}
if
(
cookies
!=
null
)
for
(
Cookie
cookie
:
cookies
)
{
if
(
cookie
.
getName
().
equals
(
name
))
return
true
;
}
return
false
;
}
...
...
src/main/java/service/IUserBudgetService.java
0 → 100644
View file @
9f52ee39
package
service
;
/**
* 维护用户与预算文件的关系
*/
public
interface
IUserBudgetService
{
}
src/main/java/service/IUserService.java
View file @
9f52ee39
...
...
@@ -5,4 +5,8 @@ import beans.User;
public
interface
IUserService
{
boolean
checkUser
(
User
user
);
boolean
existUser
(
User
user
);
void
addUser
(
User
user
);
}
src/main/java/service/impl/UserBudgetService.java
0 → 100644
View file @
9f52ee39
package
service
.
impl
;
import
service.IUserBudgetService
;
public
class
UserBudgetService
implements
IUserBudgetService
{
}
src/main/java/service/impl/UserService.java
View file @
9f52ee39
...
...
@@ -11,9 +11,22 @@ public class UserService implements IUserService {
private
IUserDao
userDao
;
@Override
public
boolean
checkUser
(
User
user
)
{
if
(
user
==
null
)
return
false
;
User
exist
=
userDao
.
selectUserByName
(
user
.
getName
());
if
(
exist
==
null
)
return
false
;
if
(
exist
==
null
||
!
exist
.
getPassword
().
equals
(
user
.
getPassword
())
)
return
false
;
user
.
setId
(
exist
.
getId
());
return
true
;
}
@Override
public
boolean
existUser
(
User
user
)
{
User
exist
=
userDao
.
selectUserByName
(
user
.
getName
());
return
exist
!=
null
;
}
@Override
public
void
addUser
(
User
user
)
{
if
(
user
==
null
)
return
;
userDao
.
insertUser
(
user
);
}
}
src/main/resources/spring-mvc.xml
View file @
9f52ee39
...
...
@@ -20,6 +20,7 @@
<mvc:interceptor>
<mvc:mapping
path=
"/**"
/>
<mvc:exclude-mapping
path=
"/Login*"
/>
<mvc:exclude-mapping
path=
"/Register*"
/>
<bean
class=
"interceptors.LoginInterceptor"
/>
</mvc:interceptor>
</mvc:interceptors>
...
...
src/main/webapp/WEB-INF/index.jsp
0 → 100644
View file @
9f52ee39
<
%@
page
contentType=
"text/html;charset=UTF-8"
language=
"java"
%
>
<html>
<head>
<title>
Index
</title>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
integrity=
"sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin=
"anonymous"
>
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link
rel=
"stylesheet"
href=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css"
integrity=
"sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin=
"anonymous"
>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script
src=
"https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
integrity=
"sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin=
"anonymous"
></script>
<link
rel=
"stylesheet"
href=
"https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css"
>
<script
src=
"https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"
></script>
<script
src=
"https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"
></script>
<style
type=
"text/css"
>
body
{
padding-top
:
70px
;
}
</style>
</head>
<body>
<nav
class=
"navbar navbar-default navbar-fixed-top"
role=
"navigation"
>
<div
class=
"container-fluid"
>
<div
class=
"navbar-header"
>
<a
class=
"navbar-brand"
href=
"#"
>
预算辅助管理系统
</a>
</div>
<div>
<ul
class=
"nav navbar-nav"
>
<li
class=
"active"
><a
href=
"#"
>
创建预算
</a></li>
<li>
<a
href=
"${pageContext.request.contextPath}/Budget/Detail"
>
修改预算
</a>
</li>
<li><a
href=
"${pageContext.request.contextPath}/Rule/"
>
修改规则
</a></li>
<li><a
href=
"${pageContext.request.contextPath}/Budget/Download"
>
导出最新预算
</a></li>
<li><a
href=
"${pageContext.request.contextPath}/Test"
>
测试
</a></li>
</ul>
</div>
</div>
</nav>
<
%
//一些默认值
int
total =
150,
equiment =
20,
material =
12,
test =
15,
power =
0,
travel =
12,
conference =
5,
international =
6,
property =
8,
labour =
66,
consultation =
2,
others =
0;
%
>
<form
class=
"form-horizontal"
method=
"post"
action=
"${pageContext.request.contextPath}/Budget/Generate"
>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
总预算(万元)
</label>
<div
class=
"col-sm-4"
>
<input
name=
"total"
type=
"number"
placeholder=
""
class=
"form-control"
required
value=
<%=total%
>
>
</div>
</div>
<hr>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"equipment"
checked
>
设备费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"equipment-number"
class=
"form-control"
type=
"number"
value=
<%=equiment%
>
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"material"
checked
>
材料费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"material-number"
class=
"form-control"
type=
"number"
value=
<%=material%
>
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"test-and-process"
checked
>
测试化验加工费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"test-and-process-number"
class=
"form-control"
type=
"number"
value=
<%=test%
>
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"power"
checked
>
燃料动力费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"power-number"
class=
"form-control"
type=
"number"
value=
<%=power%
>
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"travel"
checked
>
差旅费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"travel-number"
class=
"form-control"
type=
"number"
value=
<%=travel%
>
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"conference"
checked
>
会议费
</label>
<div
class=
"col-sm-4"
id=
"tip"
>
<input
name=
"conference-number"
class=
"form-control"
type=
"number"
value=
<%=conference%
>
>
</div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"international-communication"
checked
>
国际合作交流费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"international-communication-number"
class=
"form-control"
type=
"number"
value=
"<%=international%>"
></div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"property"
checked
>
产权费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"property-number"
class=
"form-control"
type=
"number"
value=
"<%=property%>"
></div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"labour"
checked
>
劳务费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"labour-number"
class=
"form-control"
type=
"number"
value=
"<%=labour%>"
></div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"consultation"
checked
>
咨询费
</label>
<div
class=
"col-sm-4"
>
<input
name=
"consultation-number"
class=
"form-control"
type=
"number"
value=
"<%=consultation%>"
></div>
</div>
<div
class=
"form-group"
>
<label
class=
"control-label col-sm-4"
>
<input
name=
"items"
type=
"checkbox"
value=
"others"
checked
>
其他费用
</label>
<div
class=
"col-sm-4"
>
<input
name=
"others-number"
class=
"form-control"
type=
"number"
value=
"<%=others%>"
></div>
</div>
<!-- Button -->
<div>
<button
class=
"btn btn-default btn-lg center-block"
type=
"submit"
>
生成预算
</button>
</div>
</form>
</body>
</html>
src/main/webapp/WEB-INF/web.xml
View file @
9f52ee39
...
...
@@ -67,9 +67,7 @@
<taglib-location>
/WEB-INF/x.tld
</taglib-location>
</taglib>
</jsp-config>
<!--<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>-->
<welcome-file-list>
<welcome-file/>
</welcome-file-list>
</web-app>
\ No newline at end of file
src/main/webapp/index.jsp
View file @
9f52ee39
...
...
@@ -45,6 +45,7 @@
<li><a
href=
"${pageContext.request.contextPath}/Rule/"
>
修改规则
</a></li>
<li><a
href=
"${pageContext.request.contextPath}/Budget/Download"
>
导出最新预算
</a></li>
<li><a
href=
"${pageContext.request.contextPath}/Test"
>
测试
</a></li>
<li><a
href=
"${pageContext.request.contextPath}/Logout"
>
注销
</a></li>
</ul>
</div>
</div>
...
...
src/main/webapp/login.jsp
View file @
9f52ee39
...
...
@@ -43,6 +43,7 @@
<button
type=
"button"
class=
"btn btn-default"
@
click=
"login()"
>
登录
</button>
<button
type=
"button"
class=
"btn btn-default"
@
click=
"register()"
>
注册
</button>
</form>
<p
id=
"hint"
style=
"color: red"
></p>
</div>
<script>
var
loginVue
=
new
Vue
({
...
...
@@ -62,11 +63,24 @@
{
emulateJSON
:
true
}
).
then
(
function
(
value
)
{
location
.
reload
();
},
function
(
reason
)
{
document
.
getElementById
(
"hint"
).
innerText
=
"用户名或密码不正确"
;
});
},
register
:
function
()
{
console
.
log
(
this
.
user
.
name
);
console
.
log
(
this
.
user
.
password
);
this
.
$http
.
post
(
"${pageContext.request.contextPath}/Register"
,
{
name
:
this
.
user
.
name
,
password
:
this
.
user
.
password
},
{
emulateJSON
:
true
}
).
then
(
function
(
value
)
{
location
.
reload
();
},
function
(
reason
)
{
document
.
getElementById
(
"hint"
).
innerText
=
"用户名已存在"
;
});
}
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment