本人小白,尝试写了一个SSM前后端分离工程,在后端写登录时放入了session并用println打印检查发现放入了,但是在下一个接口中调用session中的值时一直为空,再次打印发现session中的对应值已经为空了,这是怎么回事,附两个接口代码:
登录写入session正确
@RequestMapping("/login")
@ResponseBody public CommonReturnType selectUser(String telephone, String password, String state) {
User user = userService.selectByTelephone(telephone);
IsEmptyUtil isEmptyUtil =new IsEmptyUtil();
Map<String,Object> returnMsg = new HashMap<String, Object>();
if(isEmptyUtil.isEmpty(user)){
returnMsg.put("loginTips","没有该用户");
return CommonReturnType.create(returnMsg);
}else if(!(password).equals(user.getPassword())){
returnMsg.put("loginTips","密码错误");
return CommonReturnType.create(returnMsg);
}else if(!(state).equals(user.getState())){
returnMsg.put("loginTips","身份错误");
return CommonReturnType.create(returnMsg);
}
else {
this.httpServletRequest.getSession().setAttribute("BHS_LOGIN_USER",user);
returnMsg.put("user",user);
returnMsg.put("loginTips","登录成功");
System.out.println(this.httpServletRequest.getSession().getAttribute("BHS_LOGIN_USER"));
return CommonReturnType.create(returnMsg);
}
}再次使用session变为了空
@RequestMapping("/studentSubject")
@ResponseBody public CommonReturnType studentSubject(){
System.out.println(this.httpServletRequest.getSession().getAttribute("BHS_LOGIN_USER"));
User user =(User) this.httpServletRequest.getSession().getAttribute("BHS_LOGIN_USER");
if (user==null){
throw new BusinessException(EmBusinessError.PLEASE_LOGIN);
}
else {
int userId = user.getId();
Map<String, Object> map = Maps.newHashMap();
map.put("data", subjectService.selectById(userId));
return CommonReturnType.create(map);
}
}
登录写入session正确
@RequestMapping("/login")
@ResponseBody public CommonReturnType selectUser(String telephone, String password, String state) {
User user = userService.selectByTelephone(telephone);
IsEmptyUtil isEmptyUtil =new IsEmptyUtil();
Map<String,Object> returnMsg = new HashMap<String, Object>();
if(isEmptyUtil.isEmpty(user)){
returnMsg.put("loginTips","没有该用户");
return CommonReturnType.create(returnMsg);
}else if(!(password).equals(user.getPassword())){
returnMsg.put("loginTips","密码错误");
return CommonReturnType.create(returnMsg);
}else if(!(state).equals(user.getState())){
returnMsg.put("loginTips","身份错误");
return CommonReturnType.create(returnMsg);
}
else {
this.httpServletRequest.getSession().setAttribute("BHS_LOGIN_USER",user);
returnMsg.put("user",user);
returnMsg.put("loginTips","登录成功");
System.out.println(this.httpServletRequest.getSession().getAttribute("BHS_LOGIN_USER"));
return CommonReturnType.create(returnMsg);
}
}再次使用session变为了空
@RequestMapping("/studentSubject")
@ResponseBody public CommonReturnType studentSubject(){
System.out.println(this.httpServletRequest.getSession().getAttribute("BHS_LOGIN_USER"));
User user =(User) this.httpServletRequest.getSession().getAttribute("BHS_LOGIN_USER");
if (user==null){
throw new BusinessException(EmBusinessError.PLEASE_LOGIN);
}
else {
int userId = user.getId();
Map<String, Object> map = Maps.newHashMap();
map.put("data", subjectService.selectById(userId));
return CommonReturnType.create(map);
}
}
解决方案 »
- ORA-02049: timeout: distributed transaction waiting for lock
- 网站图片上传技术的代码,求
- 压缩下载问题
- 我的action怎么没执行啊?急啊!!!
- 高手快进来帮帮大忙啊!谢谢!!!!
- 对这个报错无语......你们来凭凭理!
- What's the climate lik?
- php程序和jsp程序能同时部署到一个网站上面吗?
- jb8使用自带的tomcat4.1建立webApp启动的问题!!!!
- 只学了Struts2和Hibernate...有开源的BBS练手吗?
- 用html和css外部样式制作影视简介
- [求助]Tomcat远程部署的报错问题
前端用的reaact,请求代码我贴一下,您受累看看
componentDidMount(){
this.requestList();
}
requestList = ()=> {
let _this = this;
axios.ajax({
url:'http://localhost:8080/user/studentSubject',
data:{
params:{}
}
}).then((res)=>{
if(res.status == 'success'){
let list = res.data.data.map((item,i)=>{
item.key = i;
return item;
})
this.setState({
list:list,
pagination:Utils.pagination(res,(current)=>{
_this.params.pageNo = current;// 当前页数
_this.requestList(); //刷新列表数据
})
})
}
else {
console.log(res.data.errMsg);
}
})
}
前端用的reaact,请求代码我贴一下,您受累看看
componentDidMount(){
this.requestList();
}
requestList = ()=> {
let _this = this;
axios.ajax({
url:'http://localhost:8080/user/studentSubject',
data:{
params:{}
}
}).then((res)=>{
if(res.status == 'success'){
let list = res.data.data.map((item,i)=>{
item.key = i;
return item;
})
this.setState({
list:list,
pagination:Utils.pagination(res,(current)=>{
_this.params.pageNo = current;// 当前页数
_this.requestList(); //刷新列表数据
})
})
}
else {
console.log(res.data.errMsg);
}
})
}params把sessionID设了
前端用的reaact,请求代码我贴一下,您受累看看
componentDidMount(){
this.requestList();
}
requestList = ()=> {
let _this = this;
axios.ajax({
url:'http://localhost:8080/user/studentSubject',
data:{
params:{}
}
}).then((res)=>{
if(res.status == 'success'){
let list = res.data.data.map((item,i)=>{
item.key = i;
return item;
})
this.setState({
list:list,
pagination:Utils.pagination(res,(current)=>{
_this.params.pageNo = current;// 当前页数
_this.requestList(); //刷新列表数据
})
})
}
else {
console.log(res.data.errMsg);
}
})
}params把sessionID设了
能具体说说解决方法吗?