后台findUserServlet的代码
```Object user = request.getSession().getAttribute("user");
ObjectMapper mapper = new ObjectMapper();
response.setContentType("application/json;charset=utf-8");
mapper.writeValue(response.getOutputStream(),user);
前台header.html中的代码
$(function () {
$.get("findUserServlet",{},function (data) {
var msg="欢迎回来,"+data.name;
$("#span_name").html(msg);
});
});
运行登录后出错
Uncaught TypeError: Cannot read property 'username' of null
at Object.success (<anonymous>:4:34)
at fire (jquery-3.3.1.js:3268)
at Object.fireWith [as resolveWith] (jquery-3.3.1.js:3398)
at done (jquery-3.3.1.js:9305)
at XMLHttpRequest.<anonymous> (jquery-3.3.1.js:9548)
代码上写的name的值 返回传了username的值还是空的
name的值也没传回来。求大佬详细指点一下
黑马旅游网项目获取header前台报错Uncaught TypeError: Cannot read property 'username' of null at Object.success
最新推荐文章于 2024-05-07 23:31:25 发布