SpringMVCLoginDemo1

加上上一篇拦截器文章代码综合一下



用户名:

密码:




@Controller
br/>

@Controller
@RequestMapping(value="/")
public String index() {
    return "index";
}

}

@Controller@RequestMapping(value="/auth")
br/>@RequestMapping(value="/auth")

@RequestMapping(value="/loginc",method=RequestMethod.POST)
public void LoginPage(@RequestBody Map map,HttpServletRequest request,HttpServletResponse response) {
    Map result = new HashMap();
    String userid = String.valueOf(map.get("userid"));
    String password = String.valueOf(map.get("password"));
    if(StringUtils.isEmpty(userid)) {
        result.put("flag", 0);
        result.put("msg", "userid isEmpty");
         MvcHelper.WriteResponseInfo(response,result, request.getCharacterEncoding());
    }
    if(StringUtils.isEmpty(password)) {
        result.put("flag", 0);
        result.put("msg", "password isEmpty");
         MvcHelper.WriteResponseInfo(response,result, request.getCharacterEncoding());
    }
    if("590031i".equals(userid) && "123".equals(password)) {
        result.put("flag", 1);
        HttpSession session = request.getSession();
        session.setMaxInactiveInterval(1800);  //设置过期时间,单位是秒
        session.setAttribute("userid", userid);

    }else {
        result.put("flag", 0);
        result.put("msg", "id or password error.");
    }
     MvcHelper.WriteResponseInfo(response,result, request.getCharacterEncoding());
}

@RequestMapping(value="/loginout",method=RequestMethod.POST)
public void LoginOut(@RequestBody Map map,HttpServletRequest request,HttpServletResponse response) {
    Map result = new HashMap();
    HttpSession session = request.getSession();
    session.invalidate();
    result.put("flag", 1);
     MvcHelper.WriteResponseInfo(response,result, request.getCharacterEncoding());
}

}


网页名称:SpringMVCLoginDemo1
标题URL:http://lszwz.com/article/ggejji.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款