Phase-out on the JSP (rpm)

Source: http: //1t.click/peD

And medium-sized companies need professionals, small companies need all-rounder, but for personal and professional development, I recommend separate. Java if you eat a bowl of rice in this life, is not going to study what css, js and so on.

Put your energy to focus on java, jvm principle, spring principle, mysql locks, transaction, multi-threaded, high concurrency, distributed architecture, micro-services, and related project management and so on, so that your core competencies will increasingly the higher, as the saying what you put into life, life will be back to you what.

Few have when we use the java web projects are a number of back-end framework, springmvc / struts + spring + spring jdbc / hibernate / mybatis etc.

Most of the projects are in the java backend divided into three layers, layer control (controller / action), service layer (service / manage), persistence (dao).

Layer is responsible for receiving the control parameters, call-related business layer, encapsulating the data, and routing to jsp pages. Then jsp pages using a variety of labels (jstl / el) or handwriting java (<% =%>) show up on the background data

You need to use tools such as eclipse maven or put your code labeled as a war package, and then publish the war package to a web container (tomcat / jboss / weblogic / websphere / jetty / resin) in the case of your production environment, right ?

After the release is over, you want to start your web container, began offering the service, this time you configure the domain name, dns, etc. related to your web site can be visited (assuming you are a website). 

Then we look at your front and back end code is not all that war in the bag? Including your js, css, pictures, various third-party libraries, right?

Browser, enter your website domain (www.xxx.com), then what happened?

Browser by ip route to your service, after tcp3 handshake, began a visit to your web server via tcp agreement, after your web server gets the request, began offering service request is received, then returned to your reply to by response browser. 

Then we look, let's assume that your home has 100 pictures, and query a single table, in which case the user may seem a http request, in fact, not once, when users first visit, browse there will be no buffer, your 100 images attached browser to request 100 http request (Some would say that the problem of long-chain http short chain with me, not discussed here), your web server receives the request, all this takes memory to create a socket to play tcp transmission. 

Focus here, this is the case, the pressure of your web server will be very large, because all requests are only requests a page to you this server, if one person better, concurrent access it if 10,000 people (not to talk web server cluster, here say a single instance of the web server) that you can how many servers tcp links Kang Zhu? Memory your server how much? You withstood the number of IO? Your web server points to how much memory? Will downtime?

That is why, the more medium and large web applications, the more they want to decouple.

Theoretically you can put your database application service + + + buffer + message queue users to upload log files + +, etc. are thrown on a single host, but this is like you put your eggs in one basket, risk very large.

Normal distributed architecture, is to be open, and your application server cluster (front and rear) + + database server cluster file server cluster + + Message Queue cluster cache cluster and so on.

Jsp of using pain points:

 

  1. Coupled dynamic resource and static resources all together, can not be truly static and dynamic separation. Server stress, because the server will receive various http requests, such as http request css, js, images, and dynamic code, and so on. Once the server situation occurs, it comes to an end with the front and back, the user experience is poor.

  2. After the front-end engineers do html, html needs to be modified by engineers to java jsp page, the higher the error rate (often because the page will be a lot of js code), requires both sides to co-develop when the question of amending and inefficient.

  3. jsp have to run (such as tomcat, etc.), and so can not be used in support nginx web server in java (http concurrent nginx is said that a single instance of up to 5w, use this advantage), not to mention the performance up.

  4. The first request jsp, must be compiled into a servlet in the web server, the first run will be slower.

  5. Jsp servlet access to each request are then output stream output html page, there is no direct use of high-efficiency html.

  6. There are more in the jsp tags and expressions, in the front-end engineers will be hard-pressed to modify the page, encounter a lot of pain points.

  7. If the content of many jsp page is slow to respond, because it is loaded synchronously.

 


 

Based on the above number of pain points, we should be right to develop the entire project forward weight shift, true decoupling of the front and rear end!

 


 

Before the old way is:

 

  1. Client requests

  2. servlet server or controller receives the request of (routing rules formulated by the back-end, a significant part of the entire project development right in the back end)

  3. Call service, dao business logic code completion

  4. Jsp return

  5. jsp show some dynamic code

 

The new way:

 

  1. Browser sends a request

  2. Directly to the html page (routing rules formulated by the front-end, the right to re-develop the entire project forward)

  3. html page is responsible for calling the server interface generates data (via ajax, etc.)

  4. Filling html, to show the dynamic effects.

(Interested in children's shoes can be accessed at Alibaba and other large sites, then click F12, monitoring what you refresh the page, http is how he's playing, most of them are requesting background data alone, json transmit data, rather than a large and http request to move the entire page including all returned over + static)

 


 

The advantage of this is:

 

  1. It may be true before and after the end of the decoupling front-end server using nginx. Front-end server put the css, js, images, and so on a series of static resources (You can even css, js, images and other resources into a specific file server, such as Ali cloud oss, and use the cdn acceleration), front-end server control page references, jumps, calls socket on the back, the back-end server using the tomcat. (We should use some of the front-end engineering framework such as nodejs, react, router, react, redux, webpack)

  2. Found bug, who can quickly locate the problem does not appear the phenomenon of pass the buck to each other. Page logic, jump error, browser compatibility issues, script errors, page styles and so on, all to be responsible for the front-end engineers. Interface data error, the data is not submitted successfully, the response timeout problems all solved by the backend engineer.

  3. The two sides without disturbing each other, love each other front and back of the family.

  4. In large concurrent case, I can scale horizontally while the front and rear end servers, such as Taobao will need a Home 2000 front-end server clusters to do withstood daily how many billions of daily + pv. (Go to Ali's technology summit, they said they listen to the web container are to write their own, even if he single instance of anti-concurrent http 100,000, 2,000 concurrent http 200 million, and they also can be unlimited expansion based on foreknowledge peak, terrible, it is a home ...)

  5. Concurrent reduced pressure backend server, in addition to all other interface http requests all transferred to the front nginx.

  6. Even if the back-end service is temporarily out or goes down, the front page will be a normal visit, but the data do not brush it out.

  7. Maybe you also need a micro-channel light-related applications, so you can share the interface, if there are app-related services, as long as through some code refactoring, you can also reuse a lot of interfaces, enhance efficiency.

  8. Something more is not afraid of the page display, because it is loaded asynchronously.

 


 

note:

 

  1. When the open meeting requirements, the front and rear end engineers must all participate, and the need to develop a good interface documentation, back-end engineers to write test cases, do not let your front-end engineers act as a full-time test group recommended chrome plugin postman, service layer take junit write test cases.

  2. The above-mentioned interface is not java in the interface, it plainly call interface method is to call your controler inside.

  3. Increased the workload of the team's front-end, back-end team to reduce the workload and improve the performance and scalability.

  4. We need a number of front-end framework to address similar to the nested page, pagination, page jump control. (Those of the front end of the frame mentioned above).

  5. If your project is small, or a simple network project, then you can be assured without any framework, but if your project is outside the network project, huh clatter.

  6. Before there are people in the use of similar velocity / freemarker such as template framework to generate static pages, and now this practice has also been eliminated out.

  7. The main purpose of this article is to say jsp to be eliminated in large java web projects outside the network out, did not say jsp can not completely learn, for some student friends, jsp / servlet java web and other related foundation or to grasp firmly and do you think springmvc this framework is based on what to write?

Guess you like

Origin www.cnblogs.com/BobHuang/p/11220251.html
rpm
jsp