I’m using Spring MVC 3.0 to construct a rest-style url.
Here is part of my code:
@RequestMapping(value = {"/", "/posts"}, method = RequestMethod.GET)
public String getNewestPosts(Model model, HttpServletRequest request)
throws DataAccessException {
return getPostsByPage(1, model, request);
}
@RequestMapping(value = "/posts/page/{page}", method = RequestMethod.GET)
public String getPostsByPage(@PathVariable long page, Model model,
HttpServletRequest request) throws DataAccessException {
// ... get the posts by page number
}
I wrote two methods. One handles the request from url “/posts” which means retrieving the first page of the posts , and the other one handles the request from url “/posts/page/{page}” which means retrieving the posts according to the path variable {page}.
And the problem is that all the two methods above point to the same view which is a jsp file, but they’re in different paths(“/posts, “/posts/page/xxx”). The css path (../style.css) can not adapt both of them.
I try to solve it by using absolute css path(/style.css), which means the web application works only if the application is deployed on a root path(“/”).
I would appreciate it if you could help me.
Use the
<c:url>tag, which prepends the context path to an absolute URL.or