开发者

How can I retrieve the session ID from within a JAX-RS webservice?

开发者 https://www.devze.com 2023-02-07 06:32 出处:网络
I cannot figure out how to retrieve the session ID from a given JAX-RS webservice request. I assume it is available, but I do not know h开发者_如何学Goow to retrieve it.

I cannot figure out how to retrieve the session ID from a given JAX-RS webservice request. I assume it is available, but I do not know h开发者_如何学Goow to retrieve it.

I am NOT using CXF. I would be grateful for any assistance.


You can use the @Context annotation to get the current instance of the HttpServletRequest.

@Path("/session-id.txt")
public class SessionIdResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getSessionId(@Context HttpServletRequest request) {
        return request.getSession(true).getId();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号