What is better between JSP and velocity in - Performance - Ease of use - Ease of creating reusable components - Availability of open source 3rd parties - IDE support
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I'll focus on using a template engine, because that is what I have most experience with.
It depends on what you really want to do. Servlets in combination with Velocity (or FreeMarker for that matter) offer a very good seperation of logic and presentation. Templates are harder to test, because you would need to evaluate the template to be able to judge wheter the HTML (or whatever else the output format is) is correct. For JSP this can be done in your IDE of choice.
The big advantage of templates is that you can store these completely outside of your application and even update them while your application is running. This is something that is a little harder to do with JSP, although hot deployment comes pretty close.
Reusable components can be created by using the include functionality of the template engine.
Velocity is better It adapts to many application areas It offers a simple, clear syntax for the template designer It offers a simple programming model for the developer Because templates and code are separate, you can develop and maintain them independently The Velocity engine easily integrates into any Java application environment, especially servlets Velocity enables templates to access any public method of data objects in the context
Advantages of Velocity:
The below is about Freemarker, but the comparisons are probably still relevant.
At this point in these two technologies' development, it seems like the primary reasons to choose one over the other are:
Reasons that don't seem to have as much of an impact:
Freemarker Example:
JSP-EL-JSTL Example:
The advantages of Velocity as per above miss a couple of very important things from the engineers perspective:
Those last two really make Velocity useful compared to JSP.
@Vartec: I don't think that the "strict separation of view from business logic" is a velocity feature that is not present in jsp. You can do business logic in jsp (more or less) but it's not recommended at all. But I agree in your point regarding the syntax.
Performance
JSP is compiled to Java, so I don't think that velocity is faster. (have not done benchmarks myself)
Ease of use
For designers: velocity For programmers: (IMHO) jsp, because it's closer to code
Ease of creating reusable components
JSP has lots of components Velocity has no components itself (not component oriented)
Availability of open source 3rd parties
I have seen far more projects using JSP or JSP related technologies than velocity. Maybe because velocity is really low level... :-)
IDE support
There are plenty of tools for jsp. Especially the eclipse jboss plugin/tool suite has a good jsp editor.
Plugins for Velocity are mostly not functional or pretty basic (you get lucky if you have syntax highlighting)
Update If you are looking for a templating engine now, I'd suggest to have a look at thymeleaf. It's comparably lightweight to velocity and can be used just to template some text based templates with a few lines of code or used as a full featured templating engine for example within a webapp.