如何在angularJS中使用JAVA创建的会话

如何在angularJS中使用JAVA创建的会话,java,angularjs,session,Java,Angularjs,Session,我使用以下代码在JAVA中创建会话 request.getSession().setAttribute("popMSG","Service removed successfully"); 或者在f错误的情况下 request.getSession().setAttribute("popMSGF","Oops something went wrong!"); 我需要在我的AngularJS函数中获得这个会话,代码如下 msg(value_from_angularJS) 您需要在后端代码中创建

我使用以下代码在JAVA中创建会话

request.getSession().setAttribute("popMSG","Service removed successfully");
或者在f错误的情况下

request.getSession().setAttribute("popMSGF","Oops something went wrong!");
我需要在我的AngularJS函数中获得这个会话,代码如下

msg(value_from_angularJS)

您需要在后端代码中创建另一个端点,以便客户端获取信息。例如:

public String getMessage() {
   //This is spring code may be different from your code.
   HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); // This is spring code may be different with your code.
   return request.getSession().getAttribute("popMSGF");
}

sessionStorage和HttpSession是两个不同的东西,我使用的是spring。我能够用java创建和使用会话。但是我如何直接从AngularJS访问,就像我们在JSTL或jspWell中所做的那样,JSTL或JSP在您的后端工作,而AngularJS在您的客户端站点工作。因此,除非向服务器中的会话对象提供endpoint.Ohk,否则无法直接访问该对象。目前,我尝试使用一个变量来存储数据,并将它们发送到仅发送回会话值的页面,然后使用angular接收并使用该数据。
public String getMessage() {
   //This is spring code may be different from your code.
   HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); // This is spring code may be different with your code.
   return request.getSession().getAttribute("popMSGF");
}