我在登陆后无法跳转到main页面。但login方法返回了一个json对象,但是一直进到error里。求大佬指点
@At("/login")
@Ok("jsp:pages.main")
@Filters()
public Object login(HttpServletRequest httpReq , HttpServletResponse httpRep ) {
//获取loginName、password
String loginName = httpReq.getParameter("loginName");
String password = httpReq.getParameter("password");
//获取用户信息
Map<String, Object> map = userAuthorityService.loginValid(loginName, password);
UserDTO userDTO = (UserDTO) map.get("data");
String privateUserIdentity = (String) map.get("privateUserIdentity");
String secretKey = (String) map.get("secretKey");
RedisSessionUtil redisSessionUtil = new RedisSessionUtil();
//将用户sToken及sKey写入redisSession
redisSessionUtil.putSessionValue(httpReq, httpRep, "privateUserIdentity", privateUserIdentity);
redisSessionUtil.putSessionValue(httpReq, httpRep, "secretKey", secretKey);
//读取privateUserIdentity值测试
String va=redisSessionUtil.getSessionString(httpReq, httpRep,"privateUserIdentity");
System.out.println(va);
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(userDTO);
return jsonObject;
}
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<link rel="stylesheet" href="resources/default/css/login.css" type="text/css" />
<%--<script type="text/javascript" src="/resources/js/leftnav.js"></script>--%>
<script type="text/javascript" src="/resources/frame/jquery/jquery-1.7.min.js"></script>
</head>
<body>
<!--header-->
<div class="header">
<div class="wrapper">
<div class="logo fl"></div>
<div class="per_center fr">欢迎您登录!今天是 2018年 5月4日 </div>
</div>
</div>
<!--header-->
<!--main-->
<div class="dlzc ">
<div class="wrapper zbg">
<div class="dlzc_bg">
<div class="shuru">
<form id="loginForm">
<p class="name">用户登录<color>user login</color></p>
<input class="in1" name="loginName" id="loginName" type="text" value="请输入账号">
<input class="in2" name="password" id="password" type="text" value="请输入密码">
<p><input class="width120" type="text" value="请输入验证码"><img src="resources/default/images/yzm.png"></p>
<input class="que mtop" id="btn_login" type="button" value="登录">
</form>
</div>
</div>
</div>
</div>
<!--footer-->
<div class="footer">
<p>主办:上海市养老公共服务管理平台 沪ICP备11001442号</p>
<p>地址:上海市浦东区北京西路69号 邮编:330046 咨询服务热线:12333 短信平台:1233336
</p>
</div>
<!--footer-->
<script type="text/javascript">
var loginName, password;
var dataJson;
var tempData;
function login() {
loginName = $('#loginName').val();
password = $('#password').val();
console.log(loginName + " " + password);
var postData = $('#loginForm').serialize();
$.getJSON("/login", postData, function(json){
console.log(json);
dataJson = Json.parse(json);
console.log(dataJson);
});
};
$(function () {
$('#btn_login').click(function () {
// var formData = $('#loginForm').serialize();
// $.getJSON("/login", formData, function(data){
// tempData = data;
// console.log(data);
// // dataJson = JSON.parse(data);
// // console.log(dataJson);
// });
$.ajax({
url : "/login",
type : "POST",
data : $("#loginForm").serialize(),
dataType:"json",//接受数据格式 (这里有很多,常用的有html,xml,js,json)
error : function (request) {
alert("Connection error");
},
success: function(data) {
alert("登陆成功");
console.log(data);
}
});
return false;
});
});
</script>
</body>
</html>