java response.setHeader Access-Control-Allow-Origin

java

The setHeader method of the HttpServletResponse class can be used to set the value of the Access-Control-Allow-Origin header in a HTTP response. This header is used to specify which origin (e.g., domain) is allowed to make a request to the server.

For example:

response.setHeader("Access-Control-Allow-Origin", "*");

This will allow any domain to make a request to the server. You can also specify a specific domain, like this:

response.setHeader("Access-Control-Allow-Origin", "https://www.example.com");

This will only allow requests from https://www.example.com to be made to the server.

Note that the Access-Control-Allow-Origin header should be set in the server-side code, not in the client-side code.