【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”
最近在配置spring mvc+velocity的时候发现welcome-file-list配置没有作用,请各位指教
配置文件大概如下
<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="velocity/"></property>
</bean>
resourceLoaderPath中配置了velocity模板的路径
web.xml 文件中的配置情况
<servlet>
<servlet-name>dispatcherContext</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/config/spring/applicationContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherContext</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
拦截所有的html,但在<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
配置中方为,http://localhost:8080/test 却没有进入index.html中,http://localhost:8080/test/index.html这样就ok
应该说这是 welcome-file-list 的一个不足,如果指定了 index.html 为默认首页,这这个文件必须存在于相应目录(此例为文档根目录)
解决的办法,你可以把 welcome-file 指定为 index.vm ,然后生成一个 index.vm,内容如下
#set($__nothing = $application.getRequestDispatcher("/index.html").forward($request,$response))
即可,OSChina 就是这么干的。