Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
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
yaru
fgqyxxlr
Commits
848a0a81
Commit
848a0a81
authored
Jul 02, 2018
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
若依 2.0
parent
5c9ac4e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
6 deletions
+64
-6
src/main/java/com/ruoyi/common/utils/ServletUtils.java
+53
-5
src/main/java/com/ruoyi/project/system/user/controller/LoginController.java
+11
-1
No files found.
src/main/java/com/ruoyi/common/utils/ServletUtils.java
View file @
848a0a81
package
com
.
ruoyi
.
common
.
utils
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
...
...
@@ -78,12 +79,59 @@ public class ServletUtils
}
/**
* 是否ajax
* 将字符串渲染到客户端
*
* @param response 渲染对象
* @param string 待渲染的字符串
* @return null
*/
public
boolean
isAjax
(
)
public
static
String
renderString
(
HttpServletResponse
response
,
String
string
)
{
String
header
=
getRequest
().
getHeader
(
"X-Requested-With"
);
boolean
isAjax
=
"XMLHttpRequest"
.
equalsIgnoreCase
(
header
);
return
isAjax
;
try
{
response
.
setContentType
(
"application/json"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
getWriter
().
print
(
string
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
/**
* 是否是Ajax异步请求
*
* @param request
*/
public
static
boolean
isAjaxRequest
(
HttpServletRequest
request
)
{
String
accept
=
request
.
getHeader
(
"accept"
);
if
(
accept
!=
null
&&
accept
.
indexOf
(
"application/json"
)
!=
-
1
)
{
return
true
;
}
String
xRequestedWith
=
request
.
getHeader
(
"X-Requested-With"
);
if
(
xRequestedWith
!=
null
&&
xRequestedWith
.
indexOf
(
"XMLHttpRequest"
)
!=
-
1
)
{
return
true
;
}
String
uri
=
request
.
getRequestURI
();
if
(
StringUtils
.
inStringIgnoreCase
(
uri
,
".json"
,
".xml"
))
{
return
true
;
}
String
ajax
=
request
.
getParameter
(
"__ajax"
);
if
(
StringUtils
.
inStringIgnoreCase
(
ajax
,
"json"
,
"xml"
))
{
return
true
;
}
return
false
;
}
}
src/main/java/com/ruoyi/project/system/user/controller/LoginController.java
View file @
848a0a81
package
com
.
ruoyi
.
project
.
system
.
user
.
controller
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.shiro.SecurityUtils
;
import
org.apache.shiro.authc.AuthenticationException
;
import
org.apache.shiro.authc.UsernamePasswordToken
;
import
org.apache.shiro.subject.Subject
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.ruoyi.common.utils.ServletUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.web.controller.BaseController
;
import
com.ruoyi.framework.web.domain.AjaxResult
;
...
...
@@ -22,8 +26,14 @@ public class LoginController extends BaseController
{
@GetMapping
(
"/login"
)
public
String
login
()
public
String
login
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Model
model
)
{
// 如果是Ajax请求,返回Json字符串。
if
(
ServletUtils
.
isAjaxRequest
((
HttpServletRequest
)
request
))
{
return
ServletUtils
.
renderString
(
response
,
"{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}"
);
}
return
"login"
;
}
...
...
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