***我正在尝试使用HttpSession在spring启动应用程序中实现会话管理。当我通过邮递员客户端调用Web服务时,会话属性是可访问的。但是从应用程序访问时,它将不可用。 这是我的登录页面,我在这里设置我的会话属性。
@Autowired
public HttpSession httpSession;
ClsCommon clsCommon=new ClsCommon();
private final Logger log = Logger.getLogger(this.getClass());
public static final String ACTIVE_RECORD_STATUS="A";
public static final String DEACTIVE_RECORD_STATUS="D";
@Override
public String userValidate(ClsLoginResourceDto clsLoginDto) {
List serverList = new ArrayList();
String result="";
try{
List<ClsLoginResourceBean> list=iLoginResourceRepository.userValidate(clsLoginDto.getUserName(), clsLoginDto.getPassword(), ACTIVE_RECORD_STATUS);
if(list.size()>0){
httpSession.setAttribute("COMPANY", list.get(0).getCompanyName());
httpSession.setAttribute("COMPANYID", list.get(0).getCompanyId());
httpSession.setAttribute("USERNAME", list.get(0).getUserName());
httpSession.setAttribute("USERID", list.get(0).getUserId());
httpSession.setAttribute("USERROLE", list.get(0).getUserRoleName());
httpSession.setAttribute("USERROLEID", list.get(0).getUserRoleId());
result=clsCommon.convertToJson(list);
}
else{
httpSession.invalidate();
result="failed";
}
}
catch(Exception e){
e.printStackTrace();
result="exception";
}
finally{
}
return result;
}
}
这是我的会话部分..
@Autowired
private HttpSession httpsession;
@RequestMapping(value = "/server/getData", method = RequestMethod.GET,consumes = "application/json", produces = "application/json")
public @ResponseBody String getData() {
try{
System.out.println("==server==COMPANYID=="+httpession.getAttribute("COMPANYID"));
System.out.println("==server==USERID=="+httpession.getAttribute("USERID"));
}
catch(Exception e){
e.printStackTrace();
log.error("Exception caught :"+e);
}
return "success";
}
} 如果我有任何错误,请告诉我。我是java.please的新手帮助我。***