Java堂  


Spring+Velocity中模板路径的问题

归档在: JavaPlateform — Jet @ 1:54 下午
原文出处: http://www.javatang.com/archives/2008/06/26/5407270.html
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

在Spring中使用Velocity进行视图渲染的时候需要注意一个路径的设置问题。Spring本身提供了一个用于对Velocity进行设置的类,我们做如下设置:

  1. <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  2.         <property name="configLocation" value="/WEB-INF/velocity.properties" />
  3.         <property name="resourceLoaderPath" value="/WEB-INF/templates" />
  4.     </bean>

使用configLocation属性设置了velocity配置文件的路径及文件名,而resourceLoaderPath设置了模板文件所在的位置。这里我们看到,所有的设置路径都是基于网站根目录的。

这个时候对于velocity.properties中用于设置宏文件的velocimacro.library选项而言,他所对应的目录就是前面resourceLoaderPath中设置的目录了,比如我们可以设置如下:

  1. velocimacro.library = macro.vm

并且对于模板文件中#parse指令所包含的文件也是基于resourceLoaderPath中所设置的目录。

如果我们将resourceLoaderPath设置为网站跟目录,而模板文件放在了/WEB-INF/template下,这个时候velocimacro.library和#parse指令所包含的文件路径就是基于网站根目录了,例如有个section.vm文件放在了/WEB-INF/template目录下,这个时候在模板文件中必须写成#parse(”/WEB-INF/template/section.vm”)才可以,可以看出这样非常的麻烦。

因此我们不能想当然的将resourceLoaderPath设置为网站的根目录,而是直接指向模板文件所在的目录。或许你认为我这么说有些可笑,但是有的时候我们往往在这些看似不经意的问题上浪费时间。

程序员自创的一首歌 - “Java EE 5″

归档在: JavaPlateform, Life — Jet @ 2:54 上午
Tags:
原文出处: http://www.javatang.com/archives/2006/09/18/544867.html
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!

Sun公司一名员工自己创作的歌,关于Java EE 5,很有意思的一首歌,程序员业余生活也可以这么丰富!

MP3地址:远程 本地

Ladies and gentlemen, this is Java EE 5!

One, two, three, four, five
There’s a technology I use day and night
For my application with a web frontend
They told me to use .Net
But I really don′t wanna

So many bugs I fixed last week.
My code is neat and talk is a cheap
I like Glassfish, JSF, persistence API
And as I continue you know they′re gettin′ sweeter

So what can I do I really beg you my Lord
To me codin’ it′s just like a sport
All the bad code from the past, let me dump it
Please set in the trumpet

A little bit of injection in my life
A little bit of persistence by my side
A little bit of NetBeans is all I need
A little bit of EJB’s what I see
A little bit of standards in the sun
A little bit of XML all night long
A little bit web services here I am
A little bit of code makes me real man

This is Java EE 5!

Jump up and down and move your code around
Shake your head to the sound bury bad code under ground
Move one step left and one step right
One to the front and one to the side
Refactor it once and refactor it twice
If it looks like this you’re doin′ it right

A little bit of injection in my life
A little bit of persistence by my side
A little bit of NetBeans is all I need
A little bit of EJB’s is what I see
A little bit of standards in the sun
A little bit of XML all night long
A little bit web services here I am
A little bit of code makes me real man

This is Java EE 5!

使用Velocity犯的低级错误

归档在: JavaPlateform — Jet @ 12:32 上午
原文出处: http://www.javatang.com/archives/2006/04/26/322220.html
作者: Jet Mah from Java堂
声明: 可以非商业性任意转载, 转载时请务必以超链接形式标明文章原始出处、作者信息及此声明!