使用Velocity时遇到问题。访问“/ my-website / login”链接时出现此错误:
2014-04-07 16:50:48,900 16:50:48.900 [http-bio-8181-exec-3] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/my-website/WEB-INF/views/_layouts/login.vm] in DispatcherServlet with name 'dispatcher'
我的LoginController.java
是
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView index(HttpServletRequest request) {
ModelAndView model = new ModelAndView();
model.setViewName("_layouts/login");
return model;
}
我的web.xml在这里
...
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/themes/*</url-pattern>
</servlet-mapping>
...
并且dispatcher.xml是
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.vm</value>
</property>
</bean>
那么,问题是什么?请帮帮我!
答案 0 :(得分:1)
您应该删除InternalResourceViewResolver
并使用VelocityViewResolver
。喜欢这个
您的dispatcher.xml
应该是:
<bean class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath">
<value>/WEB-INF/views/</value>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="prefix">
<value></value>
</property>
<property name="suffix">
<value>.vm</value>
</property>
<property name="toolboxConfigLocation">
<value>/WEB-INF/velocity-toolbox.xml</value>
</property>
</bean>