The solution I use in my SpringMVC webapps is to create a simple DefaultController
class like the following: -
@Controller
public class DefaultController {
private final String redirect;
public DefaultController(String redirect) {
this.redirect = redirect;
}
@RequestMapping(value = "/")
public ModelAndView redirectToMainPage() {
return new ModelAndView("redirect:/" + redirect);
}
}
The redirect can be injected in using the following spring configuration: -
<bean class="com.adoreboard.farfisa.controller.DefaultController">
<constructor-arg name="redirect" value="${default.redirect:loginController}"/>
</bean>
The ${default.redirect:loginController}
will default to loginController
but can be changed by inserting default.redirect=something_else
into a spring properties file / setting an environment variable etc.
As @Mike has mentioned above I have also: -
<welcome-file-list> ... </welcome-file-list>
section in the web.xml
file.index.html
, index.jsp
, default.html
, etc)This solution lets Spring worry more about redirects which may or may not be what you like.