Java EE Enterprise Application development The V-view view in MVC

Source: Internet
Author: User
Tags tomcat server

Step1. Overview of the situation

Hello, little friends, long time no see, before sharing with you three layers of architecture and MVC thought, I believe we have a relatively clear personal understanding of the two pieces of content, since we talked about MVC, here we continue this piece of content continues to go deeper, today we look at the V-view in MVC That is what we call the view layer.

Step2. View Technology

For our web developers, the concept of the view should not be very strange, we see in the page when the various forms of page content, behind the use of our view technology, for the Java WEB Developer, the page is actually template + data = page content, All Web pages basically inseparable from these two points, and our common view presentation layer technology does not consider this H5 page, the current market with more than basically JSP, freemarker, or velocity, for these three kinds of common view presentation layer technology, here first say JSP.

STEP3.JSP Concept and Application scenario

JSP (Java server page), hence the name Incredibles, which is the page executed on the server side, is essentially a simplified servlet that inserts Java program segments and JSP tags into a traditional web page HTML file, creating a JSP file with a suffix named (*.jsp). Saying so much is actually adding Java code on top of the HTML, running the page in the Tomcat container, and after the final project is published through the browser, the content in the browser is HTML, isn't it simple.
Here for the JSP, the concept refers to JSP is essentially a servlet, but the advent of JSP to solve a servlet pain point, is the servlet page content output is relatively troublesome, especially when it comes to complex page style control and JS, then servlet The relative change of the weak, oh, at this time the advent of JSP, to solve the serlvet of this pain point, that is: JSP as a view display layer page content more convenient! That said, JSP since is a servlet, that JSP is how to execute it?

step4.jsp Execution Process Analysis

Here, before analyzing the JSP principle, let's take a look at the internal execution principle of Serlvet

    1. The client requests through HTTP.
    2. The Web server receives the request and sends it to the servlet. If the servlet has not yet been loaded, the Web server will load it into the Java virtual machine and execute it.
    3. The servlet receives the HTTP request and performs some sort of processing.
    4. The servlet returns an answer to the Web server.
    5. The Web server sends an answer received from the servlet to the client.


The operation diagram is as follows :


See this, you should be the servlet execution process at a glance, and then we continue to look down on how the JSP operating principle



How does the server specifically do this?

    1. The user sends the request through the browser
    2. The Tomcat server receives the *.JSP request and will go to Org.apache.jasper.servlet.JspServlet processing, (Tomcat Web. xml) has a corresponding processing JSP request specific configuration



When the test01.jsp page is not accessed, look at the following Tomcat work directory:



When the JSP page is first requested, the JSP engine translates the JSP raw file into the servlet source code, then calls the Java compiler, compiles it into a servlet, and executes it in the servlet engine. When there is a request again,JSPEngine meets difference compiled goodJSPIs it better than the originalJSPOriginal file to be new, if yes, runServletIf it is not, it indicates that the file has been updated, and the conversion and compilation process will be performed anew.
test01.jsp access to the file once it has been successfully viewed again


View specific generated files in the directory



Briefly view the contents of the generated Test01_jsp.java file

View Tomcat source, see what is Httpjspbase???



At this point, it can be found that httpjspbase inherited the HttpServlet!!!
So, so far, we can understand that JSP can be regarded as a servlet to treat!!!
Since JSP is a servlet, why use JSP?

When we use the servlet, we should be able to appreciate that it is not so easy to use the servlet to output page content to the browser, and when the logic involved in the servlet is complex, both the business logic and the display of the page data are controlled. This is only possible by using Servlets to complete these functions theoretically, but for the later maintenance of the project, the amount of engineering may be huge, so the industry has spawned JSP (and of course, other technologies. Net,php, etc.) by using JSP technology, We can combine the servlet to show the data through the JSP to show, in summary:

Servlet:
Advantages: Convenient Logic processing
Cons: Page Performance Trouble
JSP:
Advantages: Convenient page performance
Cons: Logical Handling Trouble

So it should be used in a complementary way. General Project Adoption: Jsp+servlet+javabean Development method for project development OH
OK, speaking of this, I believe you have a very clear understanding of the JSP view display layer technology, the other velocity as a view layer technology is how to achieve and use it, haha, and listen to the next time to share with you.

Java EE Enterprise Application development The V-view view in MVC

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.