hi nidhi,
thanks for ur reply ,
i developed a application but i needed ur valuable guidence
it not showing any error but only index page is working
here is my application structure
+- WEB-INF
|
+- lib
| ... |
+- velocity
| |
| +- mainTemplate.vm
| +- secondaryTemplate.vm
|
+- velocityspring-servlet.xml
+- velocityspring-views.xml
+- velocity.properties
web.xml is
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Spring velocity Example </display-name>
<description>Spring velocity Example application</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!--
- Loads the root application context of this web app at startup,
- by default from "/WEB-INF/applicationContext.xml".
- Note that you need to fall back to Spring's ContextLoaderServlet for
- J2EE servers that do not follow the Servlet 2.4 initialization order.
-
- Use WebApplicationContextUtils.getWebApplicationContext(servletContext)
- to access it anywhere in the web application, outside of the framework.
-->
<!--<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderServlet</listener-class>
</listener>
<servlet>
<servlet-name>applicationContext</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>velocityspring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>velocityspring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>http://displaytag.sf.net</taglib-uri>
<taglib-location>/WEB-INF/tld/displaytag-el-12.tld</taglib-location>
</taglib>
</web-app>
velocityspring-views.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!--
Views can be hierarchical, here's an example of a parent view that
simply defines the class to use and sets a default template which
will normally be overridden in child definitions.
-->
<bean id="parentVelocityView" class="org.springframework.web.servlet.view.velocity.VelocityView">
<property name="templateName"><value>mainTemplate.vm</value></property>
</bean>
<!--
- The main view for the home page. Since we don't set a template name, the value
from the parent is used.
-->
<bean id="welcomeView" parent="parentVelocityView">
<property name="attributes">
<props>
<prop key="title">My Velocity Home Page</prop>
</props>
</property>
</bean>
<!--
- Another view - this one defines a different velocity template.
-->
<bean id="secondaryView" parent="parentVelocityView">
<property name="templateName"><value>secondaryTemplate.vm</value></property>
<property name="attributes">
<props>
<prop key="title">My Velocity Secondary Page</prop>
</props>
</property>
</bean>
</beans>
velocityspring-servlet.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="viewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="cache"><value>true</value></property>
<property name="location"><value>/WEB-INF/velocityspring-views.xml</value></property>
</bean>
<bean
id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"
singleton="true">
<property name="configLocation"><value>/WEB-INF/velocity.properties</value></property>
</bean>
</beans>
velocity.properties
Code:
#
# velocity.properties - example configuration
#
# uncomment the next two lines to load templates from the
# classpath (WEB-INF/classes)
#resource.loader=class
#class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
# comment the next two lines to stop loading templates from the
# file system
resource.loader=file
file.resource.loader.class=org.apache.velocity.runtime.resource.loader.FileResourceLoader
# additional config for file system loader only.. tell Velocity where the root
# directory is for template loading. You can define multiple root directories
# if you wish, I just use the one here. See the text below for a note about
# the ${webapp.root}
file.resource.loader.path=${webapp.root}/WEB-INF/velocity
# caching should be on in production, the following is a development
# setting only. Change to 'class.resource.loader.cache=false' for classpath
# loading
file.resource.loader.cache=false
# override default logging to direct velocity messages
# to our application log for example. Assumes you have
# defined a log4j.properties file
runtime.log.logsystem.log4j.category=com.mycompany.myapplication
applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
</beans>
secondaryTemplate.vm
Code:
## $title is set in the view definition file for this view.
<html>
<head><title>$title</title></head>
<body>
<h1>This is $title!!</h1>
</body>
</html>
plz guide me wher i did mistake
i m very new to using velocity in spring but i have to make simple demo application
in if user enter his/her name in second page i have to show welcome $user
can u give example how to write a controller for that or i can write controller like in any other spring MVC application and what r the lib we must have to set for running the application
i m using velocity-1.5.jar and velocity-dep-1.5.jar