Reputation: 19582
I recently read about Velocity
. I also read the tutorial here.
But I can not understand what is the advantage of using Velocity
.As far as I can tell we can do the same things using JSP tags.
So when one would introduce Velocity
in his project and to gain what?
Upvotes: 2
Views: 1223
Reputation: 11611
Velocity is a templating engine, JSP is (kind of) a scripting engine. The differences are quite major, although at first sight it would seem that they do the same thing, and you can abuse Velocity to really turn it into a scripting engine. The two main differentiators IMHO are:
So, neither one is clearly better than the other in all situations, you have to decide for yourself when you should use each one, and yes, they can be combined in the same project for different purposes.
IMHO Velocity works best in the following cases:
Upvotes: 3
Reputation: 375
Say you want to create a dynamic file, say a HTML file. You can either write the file in code and att the tags like
<body>
"<div>User:" + users.getUserName() + "</div>"
</body>
Or you can use Velocity to create a template file
<body>
<div>User: #user.getUserName()</div>
</body>
The benefit of doing this is that you seperate the file from the code, ie you can modify it afterwards without recompiling the code.
Upvotes: 1
Reputation: 15250
You can use it whenever you need a template for something. For example your application might send text emails to customers and an email has to be customized like this:
Dear $customerName
We announce you that tomorrow $tomorrowDate the following accounts:
#foreach ($accounts in $account)
With Velocity you can create a few email templates and than customize their content for every customer. You don't have to use it as a replacement for JSP.
Upvotes: 2