`
kl521516
  • 浏览: 5522 次
  • 来自: ...
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

关于velocity中date.format()的问题

阅读更多
不知道那个地方配置错了,或者其它问题,date.format被原样输出
以下是我的主要的两个配置文件源代码,
整个练习的数据库脚本(注:mysql数据库),以及所有源代码在附件当中,由于jar包占的内存太大,所有jar包都是空,只是一个1kb空jar包


-------------------------------web.xml中代码--------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_4.xsd" version="2.4">
	 
    <welcome-file-list>
        <welcome-file>index.vm</welcome-file>
    </welcome-file-list>	 
	 
	<!-- 配置servlet -->
	<servlet>
		<servlet-name>dispatcherServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>
				/WEB-INF/applicationContext-Service.xml,
				/WEB-INF/applicationContext-Modules-Login.xml,
				/WEB-INF/applicationContext-Modules-Client.xml,
				/WEB-INF/applicationContext-Modules-Room.xml,
				/WEB-INF/applicationContext-Modules-OpenRoom.xml
			</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatcherServlet</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>
	





	<servlet>
		<servlet-name>velocity</servlet-name>
		<servlet-class>
			org.apache.velocity.tools.view.servlet.VelocityLayoutServlet
		</servlet-class>
 
		<init-param>
			<param-name>org.apache.velocity.toolbox</param-name>
			<param-value>/WEB-INF/toolbox.xml</param-value>
		</init-param>
		<init-param>
			<param-name>org.apache.velocity.properties</param-name>
			<param-value>/WEB-INF/velocity.properties</param-value>
		</init-param>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>velocity</servlet-name>
		<url-pattern>*.vm</url-pattern>
	</servlet-mapping>	
	

	<!-- 字符编码配置 -->
	<filter>
		<filter-name>CharacterSetEncoding Filter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>GB2312</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>false</param-value>
		</init-param>
	</filter>
    <filter-mapping>
    	<filter-name>CharacterSetEncoding Filter</filter-name>
    	<url-pattern>/*</url-pattern>
    </filter-mapping>	
</web-app>

---------------------applicationContext-Service.xml中代码--------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
    "http://www.springframework.org/dtd/spring-beans.dtd">
    
<beans>

	
	
	
<!-- configure some default controllers for testing and placeholder purpose -->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
        <property name="url"><value><![CDATA[jdbc:mysql://localhost:3306/room?useUnicode=true&characterEncoding=gb2312]]></value></property>
        <property name="username"><value>root</value></property>
        <property name="password"><value>root</value></property>
    </bean>
 
  	
    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource"><ref local="dataSource"/></property>
        <!-- 实体映射文件的配置 -->
        <property name="mappingDirectoryLocations">
            <list>
                <value>classpath:/login/resources/com/login/model</value>
                <value>classpath:/client/resources/com/client/model</value>
                <value>classpath:/roommgr/resources/com/roommgr/model</value>                
                <value>classpath:/openroom/resources/com/openroom/model</value>
            </list>
        </property>
        <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>  
        </props>
        </property>
    </bean>
    
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

	<!-- the jdbcTransactionManager -->
	<bean id="jdbcTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource"><ref local="dataSource"/></property>
	</bean>
	
	
	<!-- configure a hibernate template -->
	<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory"><ref local="sessionFactory"/></property>
	</bean>
	
	
	
	
<!-- 声明一个velocity引擎 
	
	
	<bean id="velocityEngine"
		class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
		<property name="configLocation">
			<value>/WEB-INF/velocity.properties</value>
		</property>
		<property name="resourceLoaderPath">
			<value>/</value>
		</property>
	</bean>	
         
-->            
          

	<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="resourceLoaderPath">
			<value>WEB-INF/velocity</value>
		</property>
		<property name="configLocation"><value>/WEB-INF/velocity.properties</value></property>
	</bean>
 
<!-- 	配置velocity视图解析 
	<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="suffix">
			<value>.vm</value>
		</property>
		<property name="contentType" value="text/html;charset=gb2312" />
		<property name="toolboxConfigLocation"><value>/WEB-INF/velocity-toolbox.xml</value></property>		
	</bean>
      	-->  
	  
	
	<bean
		id="viewResolver"
		class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
		<property name="exposeSpringMacroHelpers"><value>true</value></property>
		<property name="exposeRequestAttributes"><value>true</value></property>
		<property name="exposeSessionAttributes"><value>true</value></property>
		<property name="requestContextAttribute"><value>rc</value></property>
		<property name="cache"><value>false</value></property>
		<property name="suffix"><value>.vm</value></property>
		<property name="contentType"><value>text/html;charset=gb2312</value></property>
		<property name="toolboxConfigLocation"><value>/WEB-INF/toolbox.xml</value></property>
	</bean> 
  
    
 </beans>
    
分享到:
评论
5 楼 kl521516 2007-07-20  
-------------------------velocity.properties配置代码-----------------------
input.encoding=GB2312
output.encoding=GB2312
#default.contentType=text/xml
default.contentType=text/html; charset=GB2312
#resource.loader=file
#file.resource.loader.class=org.apache.velocity.runtime.resource.loader.FileResourceLoader
#file.resource.loader.path = ./vm/
#file.resource.loader.cache=true 
#file.resource.loader.modificationCheckInterval=2

velocimacro.library=./vm/VM_global_library.vm

runtime.log.logsystem.class=


# Filepath for error template,
#  relative to web application root directory
tools.view.servlet.error.template=Error.htn

# Directory for layout templates,
#  relative to web application root directory
tools.view.servlet.layout.directory=vm/layout/

# Filepath of the default layout template
#  relative to the layout directory
#  NOT relative to the root directory of the webapp!
tools.view.servlet.layout.default.template=commons-layout.vm
 
4 楼 kl521516 2007-07-20  
---------------------toolbox.xml中配置代码如下--------------------
<?xml version="1.0"?>

<toolbox>
	<xhtml>true</xhtml>
	<tool>
		<key>link</key>
		<scope>request</scope>
		<class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
	</tool>

	<!-- 
		The MessageTool is used to render internationalized message strings. Source of the strings are the message resource bundles of the Struts framework. The following methods operate on these message resources. 
		
		Method Overview 
		get() Looks up and returns the localized message for the specified key.  
		exists() Checks if a message string for a specified message key exists for the user's locale.  
		
	-->
	<tool>
		<key>text</key>
		<scope>request</scope>
		<class>org.apache.velocity.tools.struts.MessageTool</class>
	</tool>
	<tool>
		<key>errors</key>
		<scope>request</scope>
		<class>org.apache.velocity.tools.struts.ErrorsTool</class>
	</tool>
	<tool>
		<key>form</key>
		<scope>request</scope>
		<class>org.apache.velocity.tools.struts.FormTool</class>
	</tool>

	<!-- 
		http://velocity.apache.org/tools/releases/1.3/generic/:	
		Example of formatting the "current" date:
		$date                         -> Oct 19, 2003 9:54:50 PM
		$date.long                    -> October 19, 2003 9:54:50 PM PDT
		$date.medium_time             -> 9:54:50 PM
		$date.full_date               -> Sunday, October 19, 2003
		$date.get('default','short')  -> Oct 19, 2003 9:54 PM
		$date.get('yyyy-M-d H:m:s')   -> 2003-10-19 21:54:50
		
		Example of formatting an arbitrary date:
		$myDate                        -> Tue Oct 07 03:14:50 PDT 2003
		$date.format('medium',$myDate) -> Oct 7, 2003 3:14:50 AM
		
	-->
	<tool>
		<key>date</key>
		<scope>application</scope>
		<class>org.apache.velocity.tools.generic.DateTool</class>
		<parameter name="format" value="yyyy-MM-dd" />
	</tool>
	<!-- 
		Tool for working with Lists and arrays in Velocity templates. It provides a method to get and set specified elements. Also provides methods to perform the following actions to Lists and arrays: 
		
		Check if it is empty. 
		Check if it contains a certain element. 
		
		Example uses:
		$primes                    -> new int[] {2, 3, 5, 7}
		$list.size($primes)        -> 4
		$list.get($primes, 2)      -> 5
		$list.set($primes, 2, 1)   -> (primes[2] becomes 1)
		$list.get($primes, 2)      -> 1
		$list.isEmpty($primes)     -> false
		$list.contains($primes, 7) -> true
	-->
	<tool>
		<key>list</key>
		<scope>application</scope>
		<class>org.apache.velocity.tools.generic.ListTool</class>
	</tool>
	<!-- 
		Single Property Sort
		#foreach($obj in $sorter.sort($objects, "name"))
		$obj.name Ordinal= $obj.ordinal
		#end
		End
		
		Multiple Property Sort
		#foreach($obj in $sorter.sort($objects, ["name", "ordinal"]))
		$obj.name, $obj.ordinal
		#end
		End
		By default the sort tool sorts ascending, you can override this by adding a sort type suffix to any property name.
		
		The supported suffixes are: 
		
		For ascending
		:asc
		For descending
		:desc
		
		Example
		#foreach($obj in $sorter.sort($objects, ["name:asc", "ordinal:desc"]))
		$obj.name, $obj.ordinal
		#end
		
		This will sort first by Name in ascending order and then by Ordinal in descending order, of course you could have left the :asc off of the 'Name' property as ascending is always the default.
	-->
	<tool>
		<key>sorter</key>
		<scope>application</scope>
		<class>org.apache.velocity.tools.generic.SortTool</class>
	</tool>

</toolbox>
3 楼 eboge 2007-07-19  
都没有看到你的VELECITY的配置文件, 没有配置怎么用哦
1 楼 sg552 2007-07-18  
看看你的日志,依照出错提示DEBUG

相关推荐

    velocity模板引擎

    同时,也可以使用`$date.format('yyyy-MM-dd HH:mm:ss', $order.createTime, $locale)`这样的形式来定制更复杂的日期格式。 #### 五、国际化支持 - **国际化**:Velocity支持国际化特性,可以通过`$locale`来获取...

    vilocity简单例子

    在这个模板中,`${page.title}`、`${user.name}`和`${lastLogin}`是来自数据模型的变量,而`${date.format}`是使用了我们在`toolbox.xml`中配置的DateTool。 总结起来,这个"vilocity简单例子"涵盖了Vilocity的基本...

    邮件模版 velocity

    - 提供了一些内置函数进行日期和数字的格式化,如 `#date.format(date, "yyyy-MM-dd")`。 - **数学** - 提供了数学函数,如加、减、乘、除等。 - **其他操作** - 提供了字符串操作,如拼接、分割等。 通过上述...

    JAVA根据模板生成WORD文件相关材料

    freemarker.template.utility.DateUtil.date_format="yyyy-MM-dd HH:mm:ss" freemarker.log.Logger=error ``` **代码示例** 下面是一个简单的Java代码片段,展示了如何使用Apache POI和FreeMarker生成Word文件: `...

    NVelocity语法 java or c#

    NVelocity支持对象的方法调用,例如`&lt;p&gt;Today is $date.format('yyyy-MM-dd')&lt;/p&gt;`,其中`date`是对象,`format`是其方法,参数 `'yyyy-MM-dd'` 定义了日期格式。 3. **条件语句**: `#{if}`, `#{elseif}`, 和 `#...

    玩转模板--自动代码生成工程

    dateTool.format('yyyy-MM-dd', ${date}) */ public class $!{tableAlias}{ #foreach($item in $columnList) private $!item.data_type $!item.column_name.toLowerCase(); // $!item.column_label #end #...

    雷达技术知识

    关于雷达方面的知识! EFFECTIVENESS OF EXTRACTING WATER SURFACE SLOPES FROM LIDAR DATA WITHIN THE ACTIVE CHANNEL: SANDY RIVER, OREGON, USA by JOHN THOMAS ENGLISH A THESIS Presented to the Department ...

    用vue实现的一个日期组件

    如果需要更复杂的交互效果,还可以引入第三方库,如`moment.js`来处理日期格式化,或者`velocity.js`来添加动画效果。 为了使组件可配置,我们可以设置一些属性(props),让外部能够传入参数来定制组件的行为。...

    Spectra带注册鸡

    3-D Surface View: displays the spectrum versus time in a 3-Dimensional perspective format. Includes solid or multicolor format. Provides an effective analysis tool for analyzing complex spectrum ...

    EasyJWeb开发介绍.ppt

    - 使用`Formatdata.parseDate`处理日期格式化。 - `xmlconfig`用于定义常用列表,如性别、省份,无需额外的类支持。 - 自动处理上传图片的显示。 - 查询列表自动处理鼠标经过和换色效果。 9. **页面交互增强**...

Global site tag (gtag.js) - Google Analytics