简体   繁体   English

使用apache velocity进行查看

[英]Using apache velocity for view

i downloaded a sample application from RoseIndia http://www.roseindia.net/tutorial/spring/spring3/web/spring-3-mvc-hello-world.html and it works fine, but i want to use apache velocity instead of jsp. 我从RoseIndia http://www.roseindia.net/tutorial/spring/spring3/web/spring-3-mvc-hello-world.html下载了一个示例应用程序,它工作正常,但我想使用apache速度而不是JSP。 what changes should i need in the current project. 我应该在当前项目中进行哪些更改。

Note: I have changed the suffix value to ".vm" instead of JSP. 注意:我已将后缀值更改为“.vm”而不是JSP。 and also view resolver to 并查看解析器

"org.springframework.web.servlet.view.velocity.VelocityViewResolver" “org.springframework.web.servlet.view.velocity.VelocityViewResolver”

i could not get the desired result, i got resource not found message. 我无法得到理想的结果,我得到了资源未找到的消息。

Here is web.xml file content 这是web.xml文件的内容

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">

<display-name>RoseIndia</display-name>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/forms/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

and servlet file contents are 和servlet文件内容是

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="net.roseindia.controllers"/>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>

</beans>

Thanks in advance, 提前致谢,

Declare 2 additional beans 声明另外两个bean

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
    <property name="resourceLoaderPath">/WEB-INF/views/</property>
</bean>    
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"/>

, and remove ,并删除

<bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix">/WEB-INF/views/</property>
       <property name="suffix">.jsp</property>
</bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM