Java Project (4)--explore similarities and differences between the two development models-model1 and MODEL2

Source: Internet
Author: User

weak and weak to say a word : JSP in the Web on the server , there should be no doubt about that. ?

first of all, look at two models in a cliché . .




Model 1 is to achieve , implementation on the line , Simple System , no architecture, just as a simple factory is not counted in 23 common design patterns. Model 1 the predecessor is



          all the business logic is written inJSPin,It's no different from a simple factory .,from an object-oriented perspective, there is no single responsibility.,does not conform to the opening and shutting principle. Model1separating the business logic,To a certain extent mitigatedJSP's Duties.but,we can seeJSPresponsible for getting page parameters,Invoking business logic,render pages, etc.,It's like we had a three-storey machine room charge system., Ulayer is responsible for obtaining data,Invoking business logic,display data, etc.,might even include some judgment on the data.,such as whether the input box is empty or not.strictly speaking .,the display layer is the one responsible for displaying the page,does not contain business logic.so, Model2separate the control Section .,thatServlet.




       looks,They're a bad one.servlet!butModel1not lessServlet,That's what I'm going to guess.,would have feltServletmust be integrated intoJSPin,Let's see a fact .:in useModel1model made in the page(assume that the page name islogin.jsp),submit the form toServletpart of the implementation code is: <form name= "MyForm" method= "post" action= "login.jsp" >Which means,it was submitted to itself.This is not a descriptionJSPit's really integrated.Servlet??

actually, Model1with theModel2The real difference is,an automatic generationServlet,a manual write.when the project was big,,Write toJSPIt's going to be a lot of clutter and chaos.,so we'll separate it.,easy to modify and maintain.

Servlet How does that work? ?

           First register servlet then map servlet external access path , through url address access web in the server servlet

<servlet>  <servlet-name>myServlet</servlet-name>  <servlet-class>myservlet</ servlet-class>  </servlet>  <servlet-mapping>  <servlet-name>myservlet</ servlet-name>  <url-pattern>/servlet/myServlet</url-pattern>  </servlet-mapping>

         We are building a newJavaafter class let him inheritHttpServlet,rewrite the insideService,thatDogetand theDoPostMethod,whenServletafter being instantiated and initialized,can process requests,will beRequestand theResponsePass as parameter,complete the following functions.

Model2is aMVCthe implementation,It's also a three-storey implementation.,I 've seen a lot of people talk about their relationship before.,Opinions.Simply put,,layer Three is a layered thought.,it represents decoupling.. MVCis an implementation,it uses three layers of thought .,And It's not the same as the classic three story .,The difference is mainly expressed in the relationship between the layers of each other called.


Java Project (4)--explore similarities and differences between the two development models-model1 and Model2

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.