Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
dae696c7
Commit
dae696c7
authored
Feb 01, 2018
by
stylefeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化session超时问题
parent
c6e0febc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
41 deletions
+0
-41
guns-admin/src/main/java/com/stylefeng/guns/core/aop/GlobalExceptionHandler.java
+0
-41
No files found.
guns-admin/src/main/java/com/stylefeng/guns/core/aop/GlobalExceptionHandler.java
View file @
dae696c7
...
...
@@ -10,8 +10,6 @@ import com.stylefeng.guns.core.shiro.ShiroKit;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.CredentialsException
;
import
org.apache.shiro.authc.DisabledAccountException
;
import
org.apache.shiro.session.InvalidSessionException
;
import
org.apache.shiro.session.UnknownSessionException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.annotation.Order
;
...
...
@@ -22,8 +20,6 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.lang.reflect.UndeclaredThrowableException
;
import
static
com
.
stylefeng
.
guns
.
core
.
support
.
HttpKit
.
getIp
;
...
...
@@ -138,41 +134,4 @@ public class GlobalExceptionHandler {
log
.
error
(
"运行时异常:"
,
e
);
return
new
ErrorTip
(
BizExceptionEnum
.
SERVER_ERROR
.
getCode
(),
BizExceptionEnum
.
SERVER_ERROR
.
getMessage
());
}
/**
* session失效的异常拦截
*
* @author stylefeng
* @Date 2017/6/7 21:02
*/
@ExceptionHandler
(
InvalidSessionException
.
class
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
String
sessionTimeout
(
InvalidSessionException
e
,
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
model
.
addAttribute
(
"tips"
,
"session超时"
);
assertAjax
(
request
,
response
);
return
"/login.html"
;
}
/**
* session异常
*
* @author stylefeng
* @Date 2017/6/7 21:02
*/
@ExceptionHandler
(
UnknownSessionException
.
class
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
String
sessionTimeout
(
UnknownSessionException
e
,
Model
model
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
model
.
addAttribute
(
"tips"
,
"session超时"
);
assertAjax
(
request
,
response
);
return
"/login.html"
;
}
private
void
assertAjax
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
(
request
.
getHeader
(
"x-requested-with"
)
!=
null
&&
request
.
getHeader
(
"x-requested-with"
).
equalsIgnoreCase
(
"XMLHttpRequest"
))
{
//如果是ajax请求响应头会有,x-requested-with
response
.
setHeader
(
"sessionstatus"
,
"timeout"
);
//在响应头设置session状态
}
}
}
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