I'm going to implement a Spring MVC controller which uses dynamic view passed as a parameter to view:
@Controller
@RequestMapping("/page")
public class PageController {
@RequestMapping(value = "/{page}", method = {RequestMethod.GET})
public ModelAndView page(@PathVariable("page")String page) {
System.out.println("page = " + page);
return new ModelAndView(page);
}
}
Views are resolved by UrlBasedViewResolver:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="cache" value="false"/>
</bean>
Is there any way to return a default view when non-existing view requested? Maybe to do check if there's no view exists, then return new ModelAndView('requested_page_not_found')
?