关于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>
<?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" 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" value="text/html;charset=gb2312" /><property name="toolboxConfigLocation"><value>/WEB-INF/velocity-toolbox.xml</value></property></bean> --> <beanid="viewResolver"name="code"><?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:50Example 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#endEndMultiple Property Sort#foreach($obj in $sorter.sort($objects, ["name", "ordinal"]))$obj.name, $obj.ordinal#endEndBy 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:ascFor descending:descExample#foreach($obj in $sorter.sort($objects, ["name:asc", "ordinal:desc"]))$obj.name, $obj.ordinal#endThis 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>input.encoding=GB2312output.encoding=GB2312#default.contentType=text/xmldefault.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=2velocimacro.library=./vm/VM_global_library.vmruntime.log.logsystem.class=# Filepath for error template,# relative to web application root directorytools.view.servlet.error.template=Error.htn# Directory for layout templates,# relative to web application root directorytools.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