Jsp,velocity,freemark Comparison of page engines

Source: Internet
Author: User

In the Java field, there are three main performance layer technologies: JSP, Freemarker, Velocity.


JSP is the most familiar technology of everyone
Advantages:
1. Powerful function, can write Java code
2. Support JSP tag (JSP tag)
3. Support Expression language (EL)
4, the official standard, a wide range of users, a wealth of third-party JSP Tag Library
5, good performance. JSP compiled into class file execution, good performance
Disadvantages:
JSP has no obvious shortcomings, it is not to pick a bone that is, because you can write Java code, such as improper use easily destroy the MVC structure.


Velocity is a template language that appears earlier to replace JSP
Advantages:
1. Cannot write Java code, can achieve strict MVC separation
2, good performance, is said to be better than JSP performance
3, using the expression language, it is said that the expression of JSP language is learning velocity
Disadvantages:
1. Not the official standard
2, user groups and third-party tag libraries do not have more JSP.
3, the JSP tag support is not good enough


Freemarker
Advantages:
1. Cannot write Java code, can achieve strict MVC separation
2, the performance is very good
3. Good support for JSP tags
4, built in a lot of common functions, easy to use
5, macro definition (like JSP tags) very convenient
6. Using an expression language
Disadvantages:
1. Not the official standard
2, user groups and third-party tag libraries do not have more JSP


Reasons to choose Freemarker:
1, performance. Velocity should be the best, followed by the JSP, and the average page Freemarker performance is the worst (albeit just a few milliseconds to more than 10 milliseconds gap). But on pages with complex pages (with a lot of judgment and date amounts formatted), Freemarker performance is better than using tag and El jsp.
2, macro definition is more convenient than JSP tag
3, built-in a lot of common functions. such as HTML filtering, date amount formatting and so on, very convenient to use
4. Support JSP Tag

5. Strict MVC separation can be achieved

The following is a less comprehensive list of features that can be implemented using Freemarker, which velocity cannot implement:
(1) Digital and date support
You can perform arithmetic operations and comparisons on any number type, including precision types
You can compare and display (format) Date/time values
(2) Internationalization
Format locally sensitive numbers based on a variety of built-in and custom digital formats
Format local sensitive and time zone sensitive dates based on a variety of built-in and custom date formats
Identifiers (variable names) can contain non-English characters, such as accented characters, Arabic characters, Chinese characters, etc.
(3) Cycle processing
Can jump out of the loop
Control variables in the loop body can be accessed outside of the loop
You can test whether the last loop was reached
(4) Array processing at the template level
Array elements can be accessed using an indexed approach like [i] syntax
Array length can be queried
(5) macro
Macros can have local variables
You can call a macro recursively, and you can also define the macro to invoke after the template
When you call a macro, you can pass parameters by location or by name
The macro parameter can have a default value, which makes it valid to ignore the parameter on invocation
The called macro can have nested body contents (< @myMacro >body</@myMacro >) that can be processed when the macro is called
A macro is a pure variable that can be executed based on an expression, or passed as a parameter to another macro
(6) namespaces
You can use multiple namespaces for variables, which is important for creating a macro library because it avoids conflicting names of variables specified in the application and in the macro library.
(7) Maintaining Java-independent string, list, and map using built-in functions/operators
You can convert a string to large/lowercase, first sizes/lowercase, to escape HTML, XML, or RTF, substring, split, query string length, Find/replace substring, and so on
Access list elements by index, get sub list, merge list, query list length, sort list
Access the map element through the key variable, check if the map is empty, get a list of keys or values
(8) Revealing errors in the template
When accessing an undefined variable, freemarker will not be silent; You can configure Freemarker to stop the render template from displaying an error message, or to skip the error section, regardless of which freemarker logs the problem (log)
Freemarker throws an exception when the wrong instruction name is written
(9) Advanced render control
A set of tags can be used to encapsulate an area of a template so that HTML or XML escapes (or other transformations expressed using freemarker expressions) are applied in all areas of the chunk to be modified
Freemarker have converters, which are an area of the template, which is filtered by conversion when render, and built-in converters include white-space character compression, HTML, and XML escape; You can implement your own converter; Of course, the converter can be nested
Flush output can be explicitly used with the flush directive
You can use the Stop command to stop render
(10) Text
In addition to the usual string, numeric, and Boolean literals, you can also define list and map literals in the template
Supports all Java escape text: \b, \ t, \ n, \f, \ r, \ ", \ ', \ \, also supports \xxxxx using Unicode to specify characters
(11) Advanced Blank character removal
Freemarker insists to remove only white space characters that contain no output freemarker tags
White-space characters are a big problem for instructions that obviously need to refurbish unwanted whitespace characters
(12) Integration of other technologies
JSP tag libraries can be used in templates
Can be used directly in the Python project
(13) Powerful XML conversion capabilities
In version 2.3, Freemarker has a powerful new XML transformation capability, making it possible to replace XSLT
Velocity is not really competitive in this area unless the core engine is improved, such as supporting the macro library mapping to namespaces, macros support local variables
(14) Advanced Template meta-Program
Can capture any part of the output into a context variable
Can explain any of the context variables if it is a template definition
The combination of the above two uses

Jsp,velocity,freemark Comparison of page engines

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.