当前位置:网站首页>登录拦截器
登录拦截器
2022-06-25 22:03:00 【-LM-】
登录拦截器
Myconfig.java
@Component
public class MyConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/","/user","/login","/echarts/**","/img/**","/layui/**","/login.html","/code");
}
}
LoginInterceptor
public class LoginInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Object user=request.getSession().getAttribute("loginUser");
if(user==null){
request.setAttribute("msg","没有权限,请先登录!");
request.getRequestDispatcher("/login").forward(request,response);
return false;
}else{
return true;
}
}
}
LoginController
// 检查登录用户身份合法性
@RequestMapping("/user")
public String user(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("captcha") String captcha,Model model, HttpSession session,HttpServletRequest request){
session = request.getSession();
String code = (String) session.getAttribute("code");
System.out.println(code);
System.out.println(captcha);
if(!captcha.equalsIgnoreCase(code.trim())){
model.addAttribute("msg","验证码错误");
return "login";
}
Map<String,Object> mp = new HashMap<>();
mp.put("username",username); mp.put("password",password);
List<User> list = loginService.checkuser(mp);
if(list.size()>0){
session.setAttribute("loginUser",username);
return "index";
}else{
model.addAttribute("msg","账号或密码错误");
return "login";
}
}
边栏推荐
- Day4 branch and loop summary and operation
- CSDN添加页内跳转和页外指定段落跳转
- C1. k-LCM (easy version)-Codeforces Round #708 (Div. 2)
- 自定义QComboBox下拉框,右对齐显示,下拉列表滑动操作
- Windows redis installation and simple use
- 录屏转gif的好用小工具ScreenToGif,免费又好用!
- My vscode
- Hibernate entity class curd, transaction operation summary
- A. Balance the Bits--Codeforces Round #712 (Div. 1)
- Spark日志分析
猜你喜欢
![Classic image segmentation network: UNET supports libtorch deployment reasoning [with code]](/img/3a/fb3bfe673db5123e3124404f3905c0.png)
Classic image segmentation network: UNET supports libtorch deployment reasoning [with code]

When are the three tools used for interface testing?

Summary of common JDBC exceptions and error solutions

Hibernate architecture introduction and environment construction (very detailed)

Hbuilderx uses the gaude map to obtain the current location

28 rounds of interviews with 10 companies in two and a half years (including byte, pinduoduo, meituan, Didi...)

(serial port Lora module) centrida rf-al42uh private protocol test at instruction test communication process

史上最简单的录屏转gif小工具LICEcap,要求不高可以试试

Konva series tutorial 2: drawing graphics

毕业旅行 | 伦敦5日游行程推荐
随机推荐
CSDN原力值
Reproduction of an implant found by Kaspersky that writes shellcode into evenlog
[opencv450 samples] read the image path list and maintain the proportional display
Implementation of sequence table: static and dynamic
Kotlin空指针Bug
Blob
Architecture part -- the use of UMI framework and DVA
Windows redis installation and simple use
Style setting when there is a separator in the qcombobox drop-down menu
自定义QComboBox下拉框,右对齐显示,下拉列表滑动操作
debezium
cookie、session、token
mongodb
golang Make a list of intervals with sequential numbers
后序线索二叉树
18亿像素火星全景超高清NASA放出,非常震撼
24class static member
【AXI】解读AXI协议原子化访问
When are the three tools used for interface testing?
记录一下Qt将少量图片输出为MP4的思路及注意事项