Model1 and Model2 are two architectural patterns of Java Web. Both of these models have pros and cons, each with their own appropriate scenarios.
Model1
First, from a hierarchical standpoint, the Model1 pattern can be thought of as being composed of two layers: the view layer and the model layer.
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "pageencoding=" GB18030 "%><%@ page import=" com.bjpowermode.drp.sysmgr.* "%><%@ page Import= "com.bjpowermode.drp.domain.*"%><%//gets the parameter string command=request.getparameter ("command"); String userid=request.getparameter ("userId");//The method that calls the query user code in the business logic is user=usermanager.getinstance (). Finduserbyid (userId);//Click Modify if ("Modify". Equals (command)) {//user user=new User (); User.setuserid ( Request.getparameter ("UserId")); User.setusername (Request.getparameter ("UserName")); User.setpassword ( Request.getparameter ("password")), User.setcontacttel (Request.getparameter ("Contacttel")); User.setemail ( Request.getparameter ("email"));//Call the method Usermanager.getinstance () that modifies the user in the business logic. ModifyUser (user); SYSTEM.OUT.PRINTLN ("modified successfully");} %>
As you can see, Model1 is a JSP-centric approach that calls a lot of business logic on JSP pages. In the example, we select a user and click Modify to submit the data to the JSP object. Then in the JSP to adjust the method of modifying the user, perform database operations, and finally return the results. This pattern reminds me of the three-story
Model2
/** * Modify the item servlet * @author Administrator * */public class Modifyitemservlet extends Abstractitemservlet {@Overrideprotect Ed void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {// Constructs the form data string Itemno=request.getparameter ("ItemNo"); String itemname=request.getparameter ("ItemName"); String spec=request.getparameter ("spec"); String Pattern=request.getparameter ("pattern"); String category=request.getparameter ("category"); String unit=request.getparameter ("unit");//Constructs the Item object item item=new item (); Item.setitemno (ItemNo); Item.setitemname ( ItemName); Item.setspec (spec); Item.setpattern (pattern);//Construction material category Itemcategory itemcategory=new itemcategory (); Itemcategory.setid (category); Item.setitemcategory (itemcategory);//Construction Material Unit Itemunit itemunit=new itemunit (); Itemunit.setid (unit); Item.setitemunit (itemunit);//Invoke Background business logic Itemmanager.modifyitem (item); Response.sendredirect ( Request.getcontextpath () + "/servlet/item/searchitemservlet");} @Overrideprotected void DoPost (HttpSErvletrequest request, HttpServletResponse response) throws Servletexception, IOException {doPost (request, Response);}}
In The example, we request the modified command from the client to the servlet, putting the method of invoking the business logic in the Modifyitemservlet.
Summary:
The Model1 is simple, easy to use and suitable for small projects. But it is because of his advantages, but also brought a great disadvantage. He brought together the business logic and performance, making the coupling much more difficult to maintain. Especially in large-scale projects, this is particularly prominent. Model2 make up for the shortcomings of Model1, in large-scale project development, can be better to achieve collaborative development of many people, non-impact.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Model1 and Model2 in Java