Consider the following code sending an HTTP 201 \"Created\" response to the client:
String url = \"/app/things?id=42\"; // example
response.setStatus(Htt
Unfortunately, the servlet API does not provide a method which directly returns the absolute URL up to with the context root. For that I have several times had to use a combination of getRequestURL(), getRequestURI() and getContextPath().
String absoluteContextRootURL = request.getRequestURL().toString().replace(request.getRequestURI().substring(1), request.getContextPath());