What is the difference between JSP and Servlet in the application? Many people are confused. Let me say a few things. Simply put, Sun first developed the servlet, which has powerful functions and advanced system design. However, it still uses the old CGI method to output HTML statements, therefore, it is inconvenient to write and modify HTML.
Later, Sun introduced an embedded JSP similar to ASP and embedded the JSP tag into an HTML statement. This greatly simplifies and facilitates the design and modification of webpages. New Network languages such as ASP, PHP, and JSP are embedded script languages.
From the perspective of a three-tier network structure, a network project can be divided into at least three layers: data layer, business layer, and presentation layer. Of course, it can be more complicated. Servlet is powerful for writing business layers, but it is inconvenient for writing presentation layers. JSP is designed to facilitate the writing of the presentation layer. Of course, you can also write a business layer. Friends who are familiar with ASP, PHP, and CGI often unconsciously mix the presentation layer and business layer. Just like the previous friend who put the database processing information in JSP, in fact, it should be placed in the business layer.
According to Sun's recommendation, JSP should only store the content related to the presentation layer, that is, only the part of the HTML webpage is output. All data computing, data analysis, and database connection processes belong to the business layer and should be placed in Java Beans. Java Beans are called through JSP to achieve integration of two layers.
In fact, Microsoft's DNA technology, simply put, is ASP + COM/DCOM technology. Similar to JSP + beans, all presentation layers are completed by ASP, and all business layers are completed by COM/DCOM. Integration is achieved through calling.
Why are these component technologies used? The simple ASP/JSP language is very inefficient for execution. If a large number of users click, the pure script language will soon reach the upper limit of its functions, the component technology can greatly increase the function ceiling and speed up the execution.
On the other hand, the pure script language merges the presentation layer and business layer, resulting in inconvenient modification and the Code cannot be reused. If you want to modify a place, it usually involves more than a dozen pages of code. You only need to modify the component by using the component technology.
To sum up, servlet is an early imperfect product. It is very good to write business layers, and it is very smelly to write presentation layers, and the two layers are mixed.
Therefore, JSP + baen is introduced, and presentation layer is written in JSP and business layer is written in baen. Sun also means replacing servlet with JSP in the future.
However, this does not mean that learning servlet is useless. In fact, you should start with Servlet, go to JSP, and then JSP + bean.
It is emphasized that after learning JSP, Java Bean will not be used for integration, which means you will not learn it. You need to make more effort on JSP + bean.
Add a few more words:
We can see that when ASP + COM and JSP + bean adopt component technology, all components are compiled first, resident in the memory, and then run quickly. Therefore, the speed advantage of the servlet/jsp that is often blown out after the memory is compiled first is no longer needed.
On the contrary, ASP + COM + IIS + nt should be closely integrated, and there should be a great speed advantage. In addition, ASP + COM + IIS + nt development efficiency is very high, although there are many bugs.