I have a JAX-RS service that I want to know what is the application context path. Before, I was using a HttpServletRequest
to get the application url, using these methods:
public static String getApplicationBaseUrl(HttpServletRequest request) {
return String.format("%s://%s:%s%s",
request.getScheme(),
request.getServerName(),
request.getServerPort(),
request.getContextPath());
}
I saw the @Context in JAX-RS, but it returns only the paths beginning from JAX resource. What can I do for retrieve the application path?
I found the answer. I was using the @Context for javax.ws.rs.core.UriInfo
class, but, I can inject the HttpServletRequest
too. So, now I can use the getApplicationBaseUrl method that I wrote.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.