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
新闻来源:http://scyanting.com/article/ggejji.html