Reputation: 411
I am using Spring MVC and I have a following method in the controller:
@RequestMapping(value = {"/web", "/web/"})
public void redirectToIndexUi(HttpServletRequest request, HttpServletResponse response) {
try {
//some condition
response.sendRedirect(request.getContextPath() + "/ui/index.html");
} catch (IOException ex) {
LOGGER.error("IOException is thrown while trying to redirect to index.html page.", ex);
}
}
When a user enters the following url http://localhost:8080/myapp/web/ redirectToIndexUi method is called, but in this case http://localhost:8080/myapp/web/index.html the redirectToIndexUi method is not called. What could be the reason ?
Upvotes: 1
Views: 592
Reputation: 10497
The reason your controller not invoked is your mapping. You are mapping your controller method to URI '/web'
and not '/web/index.html'
.
And you can use wildcard characters like '/web/**'
to point every request with /web/ in it to use your controller's method. So that your method will be called whenever your request hits anything similar to http://localhost:8080/myapp/web/**
.
Upvotes: 2