Java Project (4)-exploring the similarities and differences between the two development models-Model1 and Model2

Source: Internet
Author: User

Java Project (4)-exploring the similarities and differences between the two development models-Model1 and Model2

Weak: Should jsp be on a web server?

First of all, let's look at the two models.




<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + authorization + zcrHyrXP1izKtc/Wvs3Q0CzPtc2zvPK1pSzMuLK7yc + signature + Signature = "http://www.2cto.com/uploadfile/Collfiles/20141014/20141014091739209.jpg" alt = "\">

All the business logic is written in Jsp, which is no different from a simple factory. From an object-oriented perspective, the responsibility is not uniform and does not conform to the principle of opening/closing. model1 separates the business logic to a certain extent, reducing the jsp's responsibilities. however, we can see that jsp is responsible for obtaining page parameters, calling business logic, rendering pages, and so on. This is also like the three-tier Data Center charging system we implemented earlier, and the U layer is responsible for obtaining data, calling business logic, displaying data, and so on may even include data judgment, such as whether the input box is empty. strictly speaking, the display layer is responsible for displaying pages, excluding the business logic. therefore, Model2 separates the control part, that is, Servlet.




It looks like they are dropping a Servlet! However, Model1 does not have few servlets. If I guess at this time, I will think that the Servlet must be integrated into jsp. Let's look at the fact below: in the page created with Model1 model (assuming the Page name is login. jsp), the form is submitted to the Servlet part of the implementation code is:

That is to say, it is submitted to itself. Does this mean that jsp is actually integrated with Servlet?

In fact, the real difference between Model1 and Model2 is that one automatically generates the Servlet and one manually writes the Servlet. when the project is very large, the content written to jsp will be complicated and messy, so we will separate it for easy modification and maintenance.

How does Servlet work?

Register the Servlet first, map the external access path of the Servlet, and access the Servlet in the web server through the URL. You can configure the following in web. xml.

    
   
    myServlet
     
   
    myServlet
     
    
    
   
    myServlet
     
   
    /servlet/myServlet
     
  

After creating a java class, let the class inherit httpservlet and rewrite the Service, namely the doGet and doPost methods. After the Servlet is instantiated and initialized, the request can be processed, request and response are passed as parameters to complete subsequent functions.

Model2 is an implementation of mvc and a layer-3 implementation. Many people have discussed the relationship between them and there are different opinions. to put it simply, Layer 3 is a layered idea, which represents decoupling. MVC is an implementation. It uses the three-layer idea, and it is different from the classic three-layer. The difference is mainly manifested in the relationship between each layer and each other.


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.