I had the same problem, even after following Sinhue’s setup, but I solved it.
The problem was that that something (Tomcat?) was forwarding from “https://stackoverflow.com/” to “/index.jsp” when I had the file index.jsp in my WebContent directory. When I removed that, the request did not get forwarded anymore.
What I did to diagnose the problem was to make a catch-all request handler and printed the servlet path to the console. This showed me that even though the request I was making was for http://localhost/myapp/, the servlet path was being changed to “/index.html”. I was expecting it to be “https://stackoverflow.com/”.
@RequestMapping("*")
public String hello(HttpServletRequest request) {
System.out.println(request.getServletPath());
return "hello";
}
So in summary, the steps you need to follow are:
- In your servlet-mapping use
<url-pattern>/</url-pattern>
- In your controller use
RequestMapping("https://stackoverflow.com/")
- Get rid of welcome-file-list in web.xml
- Don’t have any files sitting in WebContent that would be considered default pages (index.html, index.jsp, default.html, etc)
Hope this helps.