I want to configure Spring MVC to serve dynamic files mixed with static files, for example (URL => File):
/iAmDynamic.html => /WEB-INF/views/iAmDynamic.html.ftl /iAmAlsoDynamic.js => /WEB-INF/views/iAmAlsoDynamic.js.ftl /iAmStatiHtml => /iAmStatic.html
DispatchServlet maps to / , annotation-based MVC configuration is enabled, and I have a view controller like this (simplified):
@Controller public class ViewController { @RequestMapping("*.html") public String handleHtml(final HttpServletRequest request) { return request.getServletPath(); } @RequestMapping("*.js") public String handleJavaScript(final HttpServletRequest request) { return request.getServletPath(); } }
Spring configuration is as follows:
<context:component-scan base-package="myPackage" /> <mvc:default-servlet-handler /> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/views/" /> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="cache" value="true" /> <property name="prefix" value="" /> <property name="suffix" value=".ftl" /> </bean>
Unfortunately this will not work. When this <mvc:default-servlet-handler /> active, I can only access the iAmStatic.html file. When I turn off the default servlet handler, then only the dynamic stuff works. But I want both at once and what should this default handler-servlet-handler do or not? Where is the mistake here?
kayahr
source share