Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of JSP?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "what is the role of JSP", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "what is the role of JSP" bar!

The era without JSP

When SUN first started to design java web, they designed servlet to handle requests and responses as a server application, and dynamically output HTML code to user-scoped HTML pages, as shown in the following figure:

Public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException {response.setContentType ("text/html"); / / Hello PrintWriter out = response.getWriter (); out.println ("); out.println (" W3Cschool618 has a course discount come and have a look "); out.println (");}

But this method does not make sense. First of all, friends who have done front-end development all know that a front-end page is prone to hundreds of lines of code. If you output it like the picture above, the back-end programmer will have to copy and paste the front-end code all the time. There will be a lot of such code in a doGet () method, which will affect the cleanliness of the code, easily disturb the programmer's logic, and some symbols will be mistakenly identified by the java compiler. Such errors take time to tune (for example, double quotation marks in HTML text will cause the string output to end prematurely, and subsequent code compilers will not compile and throw a bunch of errors). This way of writing html code in java code has been criticized by programmers, which coincides with the emergence of PHP and ASP.Net, who use an easier way to output HTML code (embedding a response language in HTML code to introduce dynamic data). As a result, many programmers switch to both languages, and java loses some of its programmers.

The birth of JSP

SUN has developed a similar technology after seeing the success of languages such as PHP, which is to be introduced next. The design philosophy of JSP is diametrically opposed to that of servlet. Servlet outputs HTML pages in java code, while JSP embeds java code in HTML code. After using JSP, web developers do not have to copy HTML pages to servlet, which not only reduces the amount of code in servlet, makes the code more concise and easy to understand, but also does not have to worry about the symbols in html being mistakenly recognized by the Java compiler (the following code should be the .jsp suffix).

JSP-Hello World learn jsp, then go to java

Compared to PHP, JSP is backed by java, because JSP is compiled into servlet at compile time, so it is essentially servlet, a servlet that solves the HTML output of servlet. Because it is servlet, it is better in performance and easier to use than PHP, a dynamically typed language.

The decline of JSP

With the introduction of Ajax, the use of Ajax for dynamic data rendering of static pages has gradually become the mainstream. Because whether it is PHP or servlet, the speed at which they generate pages is never as fast as static Apache servers that dispatch static pages, and a page often needs to render only a small part of the data. At this time, smart developers put forward a new idea: first let the Apache server dispatch a static page, and then the static page requests the server to get this part of the data to be rendered through Ajax request. Then render in the browser. In the past, the server wanted to generate a whole HTML page, but now it only needs to generate this part of the data and return it in the specified format, which greatly reduces the pressure on the server. Then many friends will find that returning data in the specified format can be easily done with servlet, while HTML static pages are directly stored in html files on static Apache servers, and the work that JSP needs to do is gone. Yes, this operation promotes the separation between the front and back ends and leads to the decline of JSP.

Thank you for your reading, the above is the content of "what is the role of JSP", after the study of this article, I believe you have a deeper understanding of the role of JSP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report