Angular 2 + Spring MVC CrossOrigin Session管理

时间:2017-11-02 12:06:57

标签: angular spring-mvc session

我从Angular 2组件调用Spring MVC控制器

let params:URLSearchParams = new URLSearchParams();
    console.log('fromDate',startDate,endDate);
    params.set('fromDate',startDate);
    params.set('toDate',endDate);
    params.set('env',environmentValue);


   return this.http.get(`http://localhost:8080/`,{search:params}).map(/*customcode*/)

这是我的控制器

@RequestMapping( method = RequestMethod.GET)
    @ResponseBody
    public String methodCall(HttpServletRequest request,
            @RequestParam String env, @RequestParam String fromDate,
            @RequestParam String toDate)  {

        List<WorkaroundDataBean> searchResult = this.delegate
                .getData(env);
        if (null != request.getSession().getAttribute("waData")) {
            request.getSession().removeAttribute("waData");
        }
        request.getSession().setAttribute("waData", searchResult);
        try {
            return this.mapper.writeValueAsString(searchResult);
        } catch (JsonProcessingException e) {

        }
    }

当我第一次调用此控制器时,它会在会话中保存数据,当我第二次再次调用时

request.getSession().getAttribute("waData")

返回null

有人可以建议可能出现的问题,角度在4200运行,控制器在8080本地运行

0 个答案:

没有答案