People think that print HTML in servlet is too troublesome, so JSP appears;
People think that the scriptlet in JSP is too powerful and confusing, so the template appears;
People think that the template function is too weak, so the template has the script language and control logic ...;
......
What do we really want ?! 92
This is a review of the template language that I have seen on the Internet. Has the template language embarked on a broken page display, undermining the old path of page development? What kind of presentation layer do we need?
Let's talk about my understanding of dynamic pages first. Dynamic Pages are the pages whose content will change subsequently. This understanding is naturally no problem, but it is meaningless to think about it. Look at the software interface of the C/S structure. A complicated interactive interface is usually a fixed layout, and dynamic data is displayed in the layout. How to standardize B/S development? Natural Dynamic Pages must also have a fixed layout, that is, static pages. Dynamic Pages only add dynamic content to the static page layout. If you understand this, you will find that many dynamic page technologies are very problematic.
Existing popular dynamic page technologies, such as JSP and script templates such as velocity and freemarker, all of which have powerful computing capabilities, but these are just the intrusion of page logic, the static page layout is destroyed, making the page difficult to maintain. In particular, the artists who are best at page creation cannot face these dynamic pages.
Most of the time I used to develop JSP files that I was keen on and familiar with, I finally got tired of it. The "omnipotent" of JSP completely disrupted the page layout, it also helped the faint pm to implement the decision of "writing business constants into the page", and the effect of tags in Dreamweaver was even worse. I realized that JSP should be abandoned. Velocity, freemarker and other advantages are also obvious to all, simple learning, convenient development (at least for programmers), and implement certain constraints to prevent the page from being written into the business layer code. However, some JSP defects still exist in the Script Template: the script continues to damage the page layout. You must start engine parsing to see the real effect, which is far from what you see. On the other hand, although its syntax is simple, it does not need to be mastered in a day. But can you be proficient in one day? Since the interface can be displayed in HTML, the background can be implemented in Java and Java is more powerful, why should we learn another so-called scripting language? (Maybe this is why many Java developers prefer JSP at the beginning ). When looking at the pages written by velocity and freemarker, I found that a large number of functions are extended: for example, you can access the request object and method, for example, you can call a Java static method by using a long string of class names and method names. These repairs and supplements for the convenience of the so-called development, not to move closer to JSP, it is simply a return to the original phenomenon! The more patches, the more away from the original intention of the template: simple.
There seems to be a consensus on whether page developers can directly participate in page development. No! After all, it's just an artist. How can the artist face scripts that cannot be understood? However, artists are good at controlling the layout and style of pages. How can they not be involved in development? In fact, the current template technology may not only support scripts such as velocity and freemarker, but also has an important branch: simple templates.
Simple templates are the so-called "too weak" templates. They only have the ability to display data, remove all page logic and computing, and have no scripts. I know that such templates, such as fastm and jdynamite, are smart imitation PHP templates and marked with annotations. Therefore, the damage to the page layout is extremely small, and the template file is a legal HTML file, you can see the effect directly in the browser (this is even better than what c/s sees, that is, income development ). Simple templates provide the possibility for the artist to directly participate in the modification of professional and beautiful pages. I think this is the true value of a simple template: it provides the possibility of division of labor for page development. In fact, this simple template technology has been used in actual development and proved to be valuable.
The advantages of simple templates are obvious:
1. better match the original intention of the template: Embed dynamic content into the static page layout to generate dynamic pages.
2. speed; the Script Template needs to be executed using a Java parsing script. For a simple template, all computation is directly performed in Java. Theoretically, the speed and efficiency of a simple template are more advantageous.
3. The engine implementation is simple, and the template page does not have the computing logic. The implementation of the natural parsing engine is much simpler. I also maintain an open-source simple template: eastm. If you want me to write a velocity, it seems more difficult :);
4. Because the page logic is implemented in the class, the reuse of the page logic is more convenient than that written on the page.
Simple templates are not all advantages, and they are not widely used because of their shortcomings.
I think the first problem is that the page is simple and the background is complicated. Make simple pages match complex data structures, resulting in a large amount of Java assembly and matching code required by the page logic layer;
In addition, the presentation capability of the template language is too weak, for example, date formatting and internationalization are not supported. It is precisely because the template display capability is too weak that the background Java computing workload increases.
To be accepted by simple templates, more improvements must be made to these two points. It is mainly to enhance the ability of the template to display data. Of course, the premise is that the template layout will not be damaged. Eastm is also making efforts in this regard.
Simple templates advocate conciseness, beautiful and simple ideas, and bring great convenience to development, especially hierarchical development, in terms of technology:
The static demo HTML page can be used in the development of the display page with a slight modification;
The artist can directly participate in the layout and beautification of the template page without worrying about the page being damaged;
You don't need to start any engines or Web Services, and you don't need to install any plug-ins. Double-click HTML to view the complete user operation interface in the browser. (This is not possible for c/s development)
Developers do not need to learn another scripting language besides HTML and Java to display data...
I firmly believe that when a simple template is simple and powerful enough, it will surely Replace the Script Template and become the mainstream of the template technology!