思路,先登陆后,将登陆信息存储在session中,然后通过拦截器,对系统中的页面和资源进行访问拦截,同时对于登陆本身相关的页面和资源不拦截。
实现方法:
12345678910111213141516171819202122232425262728293031/**
* 登陆拦截器.
*
* @author leizhimin 2014/6/26 16:08
*/
public
class
LoginInterceptor
extends
HandlerInterceptorAdapter {
private
static
final
String[] IGNORE_URI = {
"/login.jsp"
,
"/Login/"
,
"backui/"
,
"frontui/"
};
@Override
public
boolean
preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws
Exception {
boolean
flag =
false
;
String url = request.getRequestURL().toString();
System.out.println(
">>>: "
+ url);
for
(String s : IGNORE_URI) {
if
(url.contains(s)) {
flag =
true
;
break
;
}
}
if
(!flag) {
T_supplier_user user = LoginController.getLoginUser(request);
if
(user !=
null
) flag =
true
;
}
return
flag;
}
@Override
public
void
postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
throws
Exception {
super
.postHandle(request, response, handler, modelAndView);
}
}
1
2
3
4
5
6
|
<
mvc:interceptors
>
<
mvc:interceptor
>
<
mvc:mapping
path
=
"/**"
/>
<
bean
id
=
"loginInterceptor"
class
=
"net.xiucheren.web.interceptor.LoginInterceptor"
/>
</
mvc:interceptor
>
</
mvc:interceptors
>
|
本文转自 leizhimin 51CTO博客,原文链接:http://blog.51cto.com/lavasoft/1433011,如需转载请自行联系原作者