V-VIEW view in MVC, javaeev-view

Source: Internet
Author: User

V-VIEW view in MVC, javaeev-view
Step 1. scenario overview

Hello, dear friends, I have not seen you for a long time. I have shared with you the three-tier architecture and MVC ideas. I believe you have a clear understanding of the two content. Now that we have talked about MVC, here we continue to go deep into this content, today we will look at the V-VIEW in MVC that we call the view layer.

Step2. view Technology

For our WEB developers, the concept of view should not be very unfamiliar. The various forms of page content we see when browsing the WEB page are inseparable from the view technology we use, for JAVA Web developers, page display is actually template + Data = page content, and all web pages are basically inseparable from these two points, however, if we do not consider H5 pages, most of the currently popular view presentation layer technologies are JSP, Freemarker, or Velocity, for these three common view presentation layer technologies, let's talk about JSP first.
 

Step3.JSP concepts and application scenarios

JSP (java server page), hence called JSP, that is, the page executed on the server side, essentially, it is a simplified servlet. It inserts Java program segments and JSP tags in traditional webpage HTML files to form a JSP file with the suffix (*. jsp ). So many of them are actually adding JAVA code on the basis of HTML and running pages in the Tomcat (servlet) container, after the final project is published, html is output in the browser after the page is accessed through a browser, isn't it easy.
For JSP, JSP is actually a Servlet, but the appearance of JSP solves a pain point of Servlet, that is, the Servlet page content output is relatively troublesome, in particular, when it comes to complex page style control and JS, the Servlet becomes less powerful than ever. The appearance of JSP solves the pain point of Serlvet, namely: it is more convenient to display the page content as a view display layer! So now that JSP is Servlet, how does JSP actually execute it?
 

Step4.JSP Execution Process Analysis

Before analyzing the principles of JSP, let's take a look at the internal execution principles of Serlvet.


The running diagram is as follows:


As you can see, you should have a clear view of the Servlet execution process. Then let's continue to look at the running principles of JSP.


 
How is the server implemented?



When the test01.jsp page is not accessed, view the work directory in tomcat as follows:



When a JSP page is requested for the first time, the JSP Engine converts the original JSP file into the Servlet Source Code, calls the Java compiler, compiles the file into a Servlet, and runs the file in the Servlet engine. When there is another request,JSPThe engine will see the compiled differencesJSPCompare to the originalJSPThe original file should be new. If yes, runServletIf not, the file has been updated, and the conversion and compilation process will be re-executed.
Test01.jsp


View the specific files in the directory
 


Briefly view the content of the generated test01_jsp.java File
 
View the tomcat source code and check what is HttpJspbase ???


 
Now, we can find that HttpJspBase inherits HttpServlet !!!
So far, we can understand this and treat jsp as a servlet !!!
Since jsp is a servlet, why should we use jsp?

When using servlet, we should be able to understand that it is not so easy to use servlet to output page content to the browser. At the same time, when the logic involved in servlet is very complicated, it is necessary to process the business logic and control the display form of page data. In this case, only servlet can be used to complete these functions theoretically. However, for post-project maintenance, the engineering volume may be huge, so the industry has spawned jsp (of course there are other technologies. by using jsp technology, we can use servlet to display the data to be displayed through jsp. The summary is as follows:

Servlet:
Advantage: convenient logic processing
Disadvantage: page performance is troublesome
Jsp:
Advantage: convenient page performance
Disadvantage: difficult to handle Logic

Therefore, we need to use them together. General projects adopt the jsp + servlet + javabean Development Method for project development.
Well, speaking of this, I believe you have a clear understanding of the JSP view presentation layer technology. How can we implement and use the other Velocity as the view layer technology? haha, let's share it with you next time.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.