正如我在 Headers 中提到的那样,在将 Atmosphere frameworkSpring MVC 集成之后,我想通过SecurityContext(或身份验证)的帮助访问当前的LoggedIn用户,但是当我从JSP页面(客户端)发送ajax请求时,我给了null .

我的代码或其他一些问题是否有任何问题 . 下面是我的MyController.java和JSP文件

MyController.Java

@Controller
     public class MyController {


      @Autowired
      PartyManagementService partyManagementService;

    @RequestMapping(value = "/websockets", method = RequestMethod.POST)
    @ResponseBody
    public String post(final AtmosphereResource event, @RequestBody  String message)
       throws JsonGenerationException, JsonMappingException, IOException {

       User user = (User)SecurityContextHolder.getContext().
                      getAuthentication().getPrincipal();
        String username = user.getUsername();
       Person person =  partyManagementService.getPersonFromUsername(username);

      logger.info("Received message to broadcast: {}", message);
      final int noClients = event.getBroadcaster().getAtmosphereResources().size();
      event.getBroadcaster().broadcast(message);
      return " message successfully send ";
     }
    }

home.jsp

在我的家庭jsp中,我提供了一个将消息推送到服务器的ajax请求 .