Reputation: 233
I want to read a request url using spring ,i have method like below and the client request url is like http://localhost:8080/api/getName ,i want to read (/api/getName from this url)
@Controller
public class TestController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public ResponseEntity<String> getDetails(
final HttpServletRequest request,
final HttpServletResponse response) throws Exception {
}
Upvotes: 0
Views: 693
Reputation: 328604
It's a method in HttpServletRequest
: request.getRequestURL()
gives you the URL.
See this answer for some more details: How to get the request url from HttpServletRequest
To further analyse the URL, use it's methods: Parsing a URL
Upvotes: 1
Reputation: 13468
i want to read (/api/getName from this url)
For this you can use the HttpServletRequest method getRequestURI(). It will return the request URL, without the protocol/server/port part, and without the query String (the parameters).
Upvotes: 0
Reputation: 2260
You might also want to browse the api javadocs
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html
Upvotes: 0
Reputation: 20783
req.getContextPath();
Should get you the context path you are looking for.
Upvotes: 0