码迷,mamicode.com
首页 > 其他好文 > 详细

小东西

时间:2017-07-04 01:03:02      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:time   ajax   ber   map   wrong   get   string   throw   script   

<script type="text/javascript">
$(document).ready(function(){
$(‘button‘).click(function(){
var usernmae = $(‘#username‘).val();
var password = $(‘#password‘).val();
var url=‘<%=path%>/login‘;
var dataj={‘loginName‘:usernmae,‘password‘:password};
$.ajax({
type:‘POST‘,
url:url,
contentType:‘application/json;charset=utf-8‘,
dataType:‘json‘,
data:JSON.stringify(dataj),
success:function(data){
alert(data);
},
error:function(){

}
})

});

});
</script>

===============================================================================

@RequestMapping("/login")
public Object loginPost( @RequestBody User loginUser) throws Exception {
logger.info("login ");
if (StringUtils.isEmpty(loginUser.getLoginName())) {
throw new Exception("user name is null");
}
if (StringUtils.isEmpty(loginUser.getPassword())) {
throw new Exception("pwd is null");
}
Subject user = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(loginUser.getLoginName(), DigestUtils.md5Hex(loginUser.getPassword()).toCharArray());
token.setRememberMe(true);
try {
user.login(token);
} catch (UnknownAccountException e) {
throw new RuntimeException("the count not exit", e);
} catch (DisabledAccountException e) {
throw new RuntimeException("account can‘t use", e);
} catch (IncorrectCredentialsException e) {
throw new RuntimeException("pwd is wrong", e);
} catch (Throwable e) {
throw new RuntimeException("other exception", e);
}
return null;
}

 

小东西

标签:time   ajax   ber   map   wrong   get   string   throw   script   

原文地址:http://www.cnblogs.com/developer-os/p/7113601.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!