Discussion on the difference between jsp and servlet

  • 2020-06-15 10:05:32
  • OfStack

Answer 1:

The first thing you need to understand is servlet. servlet is an java program that runs on the server, but has a set of rules (commonly known as api). To put it simply, jsp is an servlet program written with another set of simple rules. It can write java code, html code, JavaScript, css and so on... But on the server side it is first converted to servlet and then executed in the same order as servlet.

Answer 2:

The following are from the Internet:
What exactly is the difference between JSP and SERVLET in terms of application is unclear to many. Let me give you some baloney. To put it simply, SUN first developed SERVLET. Its functions are relatively strong and the system design is very advanced. However, it still adopts the old CGI way to output HTML sentences one by one, so it is very inconvenient to write and modify HTML.
Later, SUN launched JSP, which is similar to ASP's tessellation type, embedding JSP TAG into HTML statement, which greatly simplifies and facilitates the design and modification of web pages. New network languages such as ASP, PHP and JSP are Mosaic SCRIPT languages.

From the perspective of three-layer network structure, a network project has at least three layers: data layer,business layer and presentation layer. It could be more complicated. SERVLET is very powerful for writing business layer, but it is very inconvenient for writing presentation layer. JSP was designed mainly for the convenience of writing presentation layer. Or, of course, business layer. Used to writing ASP, PHP, CGI friends, often unconsciously presentation layer and business layer mixed together. Like the previous friend, put the database processing information in JSP, when it should be in business layer.
According to SUN's own recommendation, JSP should store only the parts related to presentation layer, that is, only the parts that output HTML pages. All data calculation, data analysis and database join processing belong to business layer and should be placed in JAVA BEANS. By calling JAVA BEANS via JSP, the two-layer integration is achieved.
In fact, Microsoft recently launched DNA technology, simply put, ASP+COM/DCOM technology. Exactly like JSP+BEANS, all presentation layer was completed by ASP and all business layer by COM/DCOM. The integration is achieved through invocation.
Why adopt these component technologies? Because the pure ASP/JSP language is executed very inefficiently, if a large number of users click on it, the pure SCRIPT language will soon reach its function limit, while component technology can greatly improve the function limit and speed up the execution speed.

On the other hand, the pure SCRIPT language mixes presentation layer and business layer together, making it difficult to modify and the code cannot be reused. If you want to change one place, which often involves more than 10 pages of CODE, you can simply reorganize the pieces using component technology.
To sum up, SERVLET is an early and imperfect product. Writing business layer is good and writing presentation layer stinks and has two layers mixed together.
So JSP+BAEN, JSP, presentation layer, business layer. SUN itself means that JSP will replace SERVLET in the future.
However, this does not mean that learning SERVLET is useless, in fact, you should start from SERVLET, then JSP, then JSP+BEAN.
It is emphasized that learning JSP but not using JAVA BEAN and integrating it means not learning. So let's put a little more effort into JSP+BEAN.

In addition:

We can see that when both ASP+COM and JSP+BEAN adopt component technology, all components are compiled, reside in memory, and then executed quickly. As a result, the much-touted SERVLET/JSP speed advantage of first compiling in memory and then executing is lost.
On the contrary, with the close integration of ASP+COM+IIS+NT, a large speed advantage should be presented. Also, ASP+COM+IIS+NT is very efficient to develop, although BUG is a lot.

So why JSP+BEAN? Because JAVA has a great future. After the Microsoft spin-off, the operating system will be dominated by a group of developers, application software developers must find a common development language to develop, JAVA1 is the time to rule the world. If the Microsoft spin-off goes well, the app companies that will emerge from it will be the new leaders in JAVA. The current JAVA is disappointingly lacklustre. I hope the new company will breathe new life into it. However, it is likely that the new company will fight with the old JAVA standard, with each side setting its own standard and influencing the JAVA platform.
In addition, the JAVA's speed disadvantage can be quickly overcome with faster and faster machines.

Related articles: