M. Thiele M. Thiele - 1 year ago 157
Java Question

Set-Cookie header is not set

I want to receive a response from my server with a Set-Cookie header. I'm using Jersey, spring-boot and Spring security on the server side and angular 2 on the client side. I receive the response, but the Set-Cookie header is not set. It's only in the metadata:


But there is no "Set-Cookie" Header:

That's the code from the response:

return Response.ok().cookie(new NewCookie("SomeName", "someId")).build();

The method ".header(..)" isn't working as well.

Answer Source

Try it like this

public ResponseEntity<?> resourceFunction(HttpServletResponse response) {
    response.addCookie(new Cookie("SomeName", "someId"));
    return ResponseEntity.ok().build();

Snippet from Chrome DevTool

ResponseEntity, HttpServletResponse and Cookie are imported from javax.servlet.http.*

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download