小东西
Posted developer_os
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小东西相关的知识,希望对你有一定的参考价值。
<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;
}
以上是关于小东西的主要内容,如果未能解决你的问题,请参考以下文章