0

在我的 web 服务类 using(jersey)中,@Context我注入了用于身份验证的对象,我称之为servlet。HttpServletRequestHttpServletResponseServletContextValidateUser

@Path("/server")
public class WebServer { 
    @Context 
    private ServletContext context; 

    @Context
    private HttpServletRequest request;

    @Context
    private HttpServletResponse response;

    @POST
    @Path("/auth")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response createTrackInJSON(Track track) throws IOException, ServletException{ 
    ....
    context.getRequestDispatcher("/ValidateUser")include(request, response);
    ...
    }        
}

在 ValidateUser.java 中,我在验证后创建了会话:

HttpSession session = request.getSession(true);

到目前为止一切正常,但是当我打电话时:

HttpSession session = request.getSession(false);
session.invalidate();

在注销 Servlet 会话中是null. 我知道 RESTful Web 服务是无状态的,但我需要在服务器端维护会话有什么办法可以实现吗?@PerSession注释呢?在这种情况下会有用吗?

4

1 回答 1

0

以下是调试会话的一些方法:

  • 您能看到在您的客户端上创建的会话 cookie 吗?
  • 你确定你没有使用多个前端吗?也许您需要将会话持久化到数据库?
  • 会话是否已超时?验证调用和注销之间可能需要很长时间吗?

@PerSession 注释呢?在这种情况下会有用吗?

@PerSession使用相同的基础会话信息。我不认为它会解决你的问题。

于 2013-03-25T16:59:15.497 回答