Xiaolong Pavilion Blueski compile
(Editor: The original text of this article first out of foreign countries, JSP is only a kind of technology that has just emerged, and it is not like this. Now it seems that some views of this article may have certain limitations, but I have to admit that this is a very atmospheric work involving many JSP's internal principles. Therefore, I still need to introduce this article to everyone so that you can understand JSP technology from another side.)
Now every developer using servlets knows JSP, a Web technology that is invented by Sun's invented and spending a lot of effort to implement on SUN technology. JSP offers the HTML code in the servlet, so that web application development and page maintenance can be accelerated. In fact, the official "Application Development Model" document released by Sun: "JSP technology should be considered standard, while servlets can be considered as a supplement in most cases."
This article will compare JSP and another servlets-based technology: Template Engines.
Direct use of servlets
When servlets are invented, the entire world has seen its superiority. Servlet-based dynamic web pages can be quickly executed, can be easily transferred between multiple servers, and can be perfectly integrated with the background database, so servlets is widely accepted as a preferred platform for a web server side.
However, the HTML code that is usually implemented by a simple manner is now ready to call each line HTML line through out.println (), which becomes a serious problem in the actual servlet application. HTML content has to be implemented through code, which is a heavy time when it is a heavy cost. In addition, those responsible for web content have to ask developers to do all updates. To this end, people seek this better solution.
JSP is born
JSP 0.90 was born. In this technique, you can embed Java code into the HTML file, and the server will automatically create a servlet to the page. JSP is considered to be a simple way to write a servlet. All HTMLs can be directly obtained without having to call out of Out.println (), and those responsible for page content can directly modify HTML without having to break the risk of Java code.
However, letting the page art designer and developers work is not ideal in the same document, so that Java embeds HTML proves to be as embarrassing like HTML embedding Java. Reading a pile of chaotic code is still a difficult thing.
Thus, people use JSP to mature and use JavaBeans more. Beans contains the business rule of service required by JSP. Most of the code in JSP can be taken out in the bean, and only a minimal mark is used to call the bean.
Recently, people began to think that JSP pages in this approach is really like views. They become a component for displaying the client request results. So people will think, why not send requests directly to View? Target View If the request is not appropriate? Say, a lot of requests have 挚 芾> Media 峁鹶 峁鹶 峁鹶 视. For example, the same request may produce a successful page, a database exceptional error report, or an error report for missing parameters. The same request may generate an English page or the Spanish page, depending on the client's Locale. Why do the client must send the request to View directly? Why should the client should send the request to some universal server components and let the server to determine the return of the JSP View?
This allows many people to accept design known as "Model 2", which is a model-based model-based model defined in JSP 0.92. In this design, the request is sent to a servlet controller that performs commercial labeling and generates a similar data "model" for display. This data is then sent to a JSP "View" to display, which looks like a JSP page is an ordinary embedded JavaBean. The appropriate JSP page can be selected based on the internal logic of the SERVLET responsible for control. In this way, the JSP file has become a beautiful template view. This is another development and is admired by another developer. Enter Template Engines
If you use Template Engine to replace the JSP of the usual purpose, the next design will become simple, the syntax is simpler, and the error message is more readily read, the tool is more user-friendly. Some companies have made such engines, the most famous may be Webmacro, and their engine is free.
The developer should be clear, select a Template Engine to replace JSP to provide the following technical advantages, and these are also the shortcomings of JSP:
Question # 1: Java code is too template, although it is considered a bad design, JSP still tries to join the Java code to the web page. This is something like Java has done, that is, simplified modifications to C , Template Engines also simplifies the source code of the lower layer in JSP. Template Engines implements a better design. Question # 2: Requires Write Java code to write some Java code in the JSP page. For example, suppose a page is to determine the context of the root in the current web application to guide its homepage, it is best to use the JAVA code in JSP: home Page You can try to avoid Java code, and use the
The best way in JSP is: <% string title = "the page title";%> <% @ include file = "/ header.jsp"%> ... Your page content ... <% @ include file = "/ footer.jsp"%> page designer To remember that you cannot miss the first line of semicolons and to define Title as a string. In addition, / header.jsp and /footer.jsp must be in the root directory and must be an accessible full file. In WebMacro contains Headers and Footers to do more simple: #set $ title = "The page title" #parse "Header.WM" Your Content Here #Parse "Footer.WM" This is not to keep in mind for the designer Number or definition of Title, .wm file can be placed under a customizable search path. Question # 4: Very rough loop is difficult in JSP. Here is to repeat each ISP object name with JSP. <% Enumeration e = list.elements ();
While (E.haASMoreElements ()) {
Out.print ("The next name is");
Out.println ((ISP) E.NEXTELEMENT ()). getName ());
Out.print ("
");
}
%> Maybe there is a user-defined tag to do these loops. This is also true for "if". The JSP page may seem to have a very quirky Java code. At the same time, the Webmacro loop is very beautiful: #Foreach $ ISPIS $ ISPS {The next name is $ isp.name} If necessary, the # foreach directive can be kept in custom # foreach-backwards instructions. If you use JSP, it is likely to change this: (Here is a possible
In fact, the hard disk space is doubled. Considering that the JSP file can easily pass <% @ include> to include a large data file, such attention is very meaningful. At the same time, each JSP class file data must be loaded into the server's memory, which means that the server's memory must save the entire JSP document tree forever. A small number of JVMs have the ability to remove class file data from memory; however, programmers typically cannot control such rules to refine, and re-disclosing to large sites may not be very effective. Space is saved because there is no second file to be produced. Template Engines also provides programmers to provide full control of Templates in memory. There are also some problems with Template Engine
Template's problem # 1: There is no strict definition of Template Engine how work is not strictly defined. However, but relatively JSP, this is not very important, and the JSP is different. Template Engines does not have any special requirements for web servers - any support for servlets can support Template Engines (including API 2.0 servers such as apache / JSERV, they can't fully support JSP)! If you design a healthy competition for the best Template Engine can cause a dazzling innovation, especially the promotion of open source, (you can push and promote ideas), then Today's WebMacro will be like Perl, without strict definition but the promotion of public code organization is its standard. Template's question # 2: Nothing to recognize Template Engines has not been widely known. JSP has occupied a great commercial market and deep into the hearts. And G Template Engines can only be an unprecedented alternative technology. Template's problem # 3: Nice Template Engines has not been highly adjusted. There is no performance test and comparison for both Template Engine and JSP. Theoretically, a good Template Engine implementation should match a non-formation JSP; however, considering that third parties have made such a far-reaching promotion, and the result is that JSP is well adjusted well.
JSP role
Of course, JSP will necessarily have its position. Even from the name, it can also be seen from the similarity of JSP and ASP, they only have a difference in letters. So if you want to use ASP to turn to Java, very similar JSP environments will play a lot of role in this, and the ASP can maintain this corresponding relationship can also be launched by the designer of JSP. Taken into account.
However, it is necessary to emphasize that it is conducive to transfer to the new environment, and whether the best way to use this environment is used.
The development of JSP has become increasingly shown that it is one of the most important Java technology, which makes people leave the world of ASP - From this, Sun will support this strong commercial CASE, Java related technical supporters will also give more Vigorously support.
Unfortunately, this is actually the best solution for this Java platform. This will make the Java solution seem to be a solution without Java.