How to set cookie in Jersey?

前端 未结 1 908
粉色の甜心
粉色の甜心 2020-12-15 11:13

I am using jersey jax-rs in myeclipse as backend of my project and jsp as frontend. I want to set cookie from server after successful login. In the jersey\'s official docume

相关标签:
1条回答
  • 2020-12-15 11:31

    To set the cookie in your example, you can do something like this:

    return Response.ok(new Viewable("/index", model))
                   .cookie(new NewCookie("name", "Hello, world!"))
                   .build();
    

    But if you want to redirect to "/" you would also need to return 3xx response instead of 200, for example:

    return Response.seeOther("/")
                   .cookie(new NewCookie("name", "Hello, world!"))
                   .build();
    
    0 讨论(0)
提交回复
热议问题