「Spring」Cannot create a session after the response has been committedの解決方法

サンプルコード

@RequestMapping(value={"","/"})
    public String index(HttpServletResponse response,HttpServletRequest request) throws Exception{
        String callbackurl = request.getRequestURL().toString();
        Authorize cft = new Authorize(appKey, appSecret);
        String code = request.getParameter("code");
        String url = cft.forwardurl(callbackurl, "test", Authorize.DISPLAY_TAG_T.WEB);
        if ( code == null || code.isEmpty() ){
            /** return null対策*/
            response.sendRedirect(url);
            return null;
        }else{
            String text=au.querytoken(code, callbackurl);
            Map<String, Object> map=JSON.parseObject(text);
            String token=(String) map.get("access_token");
            if(token==null){
                response.sendRedirect(url);
                return null;
            }else{
                User user=new User(token);
                System.out.println(user.me());
                System.out.println(text+"--------------");
            }
        }
        return "user/guide";
    }

 

Java

Posted by arkgame