Why use frameworks?

    Now do the project will use the framework, it is now common framework is SSH (Struts + SpringMVC + Spring + Hibernate), SSM (Struts / springMVC + Spring + Hibernate), and I recently did a project itoo using the framework for easyUI + SpringMVC + EJB + hibernate. Layering is doing the project in order to better decouple, you do not completely hierarchical framework can be solved, why so many frameworks do not need it?

 

    And many companies now control layer web technology framework project to migrate from struts2 springMVC, why we are doing java web development, would choose such a framework struts2 or springMVC, instead of using such technology servlet jsp add it? Especially now that we are using a web front page of such velocity template language development, abandoned jsp, this choice will give us java web development what kind of benefits, the issue of the extension of the idea, I found the new question, why a lot of java enterprise level development will be to select the spring framework, spring framework for application development has brought us what? Such a depth would like to really do not want to understand, I can seem difficult to find a bunch of people completely convincing answers, eventually I found that I think I'm very familiar with commonly used technique, in fact, there are many strange let me understand where these strange and puzzling place is what if I can use a higher level of their key, but struts2, this spring after so many years of technical accumulation is quite large and complex, they are very broad , although I have been using them for a long time, there are still many technical unfamiliar and unclear.

    There is a very general framework for the use of the benefits: First, it can speed up the development process, developers reuse code will save a lot of time and effort in similar projects in the framework of providing pre-built module to perform the tedious task of this benefit in the code. a framework which is very useful. but go down deep thinking about?

  In fact, there are many excellent software framework, there is one type of framework, which is characterized by the establishment of a technology framework based on the prior art, as in the prior art and provide business functions, this new technology framework than the original technology easier to use, more robust and more powerful at the same time, for example: jQuery, and this paper is to talk about the struts2 and springMVC, get to the bottom of these frameworks are quite complex, but their advantage is only one: that allows users to only care about the core business development framework to help you shield a variety of technical problems with the existing technology business development independent. Like jQuery, struts2 or springMVC good reason why this type of framework, that is, at this point they do good, that many programmers have been using it do not know the true face of the existing technology, so we want to understand struts2 better, more skilled and in-depth use, where we have to jump out struts2 technologies to struts2 source servlet technology, under the careful study of the characteristics of servlet, the only way we can learn to better struts2 framework.

 

  Servlet action is a request (request) to the service browser receiver side, the response (response) server and processed returned to the user's browser, the browser and the server communicate via the http protocol, the process is browser according to a user's selection information by http packet http protocol packets specification assembly request packet to the specified server, the server receives this message information through a particular web container through the network transmission, for example: tomcat, jetty after, such JBoss web container, the container will http web parsed packet, if the user requests, the final parsed message information is stored together with a request object, the server uses this corresponding processing request finish, service end of the program will result in the information package subject to the response, then the response to the target web container, web container put the object into the response packet http protocol, and message back to the browser, the browser finally resolve this response packet, the final results to the user.

 

  Web servlet container creates an interface, the interface is the servlet developers place their own business logic implementation, programmers servlet meant doing fill-in, and fill-in the context or the context is prompted by the request and response objects, but the norm in javaEE the servlet interface is very simple, three methods init, service and destory, but this interface is too general, it also provides a specification in HttpServlet class that provides doGet, doPost methods according to the type of http request, servlet interfaces largest it is characterized according to the characteristics of the http protocol definition, and therefore do servlet development time if the user of the http protocol features are not particularly familiar with, will encounter more or less confusing issues, especially the complex met with some special requests when: such as file upload, returned special file format to the browser, this time using a servlet development is not very convenient, servlet developers there is a problem and we may often overlooked, is the type of data conversion request, http agreement transmission are text form, to the web container is resolved after Text type, if you encounter currency, numbers, dates of the type we need to be converted according to the actual situation, if the information pages transmitted very much, we have to do a lot of type conversion, this work is no technical content, is a physical work and can easily lead to program errors. Meanwhile java enterprise development are carried out around javabean, type conversion also good data package to the corresponding javabean, this kind of thing and turn for project development is definitely not a good thing, so this problem is the old struts1 to find a solution, it is the definition of a DTO objects (data transfer objects), responsible for doing such a thing, but to struts2, the entire replacement of action is itself a servlet javabean.

 

  Enterprise Java development is the use of a technical features javabean carried out, it is one of the characteristics struts2 alternative class of operation is a typical servlet javabean, struts2 first page of data frame transmission is performed after the package and the type of conversion request information to the package this javabean properties where we develop web applications eliminating the need for time to worry about the problem and the type of conversion package, I spoke in front of a traditional servlet is defined according to the http protocol, it will be according to your request method (post or get way) to handle the user's request, but for a program developer, a request to a specific url, in fact, for the server concerned is a function provided by the external server, or a server-side action is external if we use servlet development process we have to put http movements into specific business action, which allows an application developer become complicated, and enhance the difficulty of development, so struts2 replace the servlet javabean servlet request to shield the inside of http specific business problems and ways of transforming action, javabea n in each and every method can be a url for each request, which will inevitably reduce the difficulty of the problem developed.

 

    Another role is to construct Servlet response object, allowing the page to get the correct response, in fact, a modern browser is a multimedia tool, text, images, screen and so everything can be displayed in the browser, different resources will lead to http response difference in the packet, if we use servlet developers to be dealt with in the form of hard-coded according to different resources in the java program, such a program is difficult to reuse, and treatment for certain if the programmer does not understand the resources in place, cause problems arise, struts2 in the form of such a configuration file from a java program logic stripped out, the use of unified management configuration, similar to the approach of spring and AOP way, so let the result of a more unified approach, more conducive to management, but also enhance the robustness of the program and reduce the difficulty of development.

 

  Servlet MVC development model in which there is a layer C that is the control layer, the control layer as Russia's double-headed eagle (a head east to see a head west to see) as a first look at the M-layer model layer, a head to V layer look at the view layer, model layer is written in java, the control layer also belong to develop server-side language, so communication M and C layers of no natural barriers, but the view layer and layer V is not the same, it's a cross verbal communication, to the browser, it only know html, javascript and css, java browser can not understand the language thing, but let the server browser to understand what can be accepted, we have to respond to the service side of information into the page, and therefore requires a java technical information transformed into the html page, this is the norm in javaEE provides jsp technology, in fact, is a server-side jsp technology rather than client-side technology, but it seems like html technology, first developed in the jsp java code is written directly to the page where this harm everyone knows, after javaEE specification provides a custom label technology, use Similar kinds of ways to parse html tags java code, struts2 framework provides a complete set of custom label technology, which does not sound seems Suansha, but its role is extraordinary, because the custom tag was called the custom is that everyone can themselves be defined, if not a specification inevitable confusion, but also a perfect custom label is a systematic project, a complete set of custom tag equivalent to our own people define a new set of development languages, do the procedure in this must hear will understand the development of a complete set of workload and difficulty of developing custom labels are hard to imagine, but a custom label and the control layer are closely linked, the difficulty will increase a dimension, so struts2 provided custom label for business development will be brought about a qualitative leap.

 

  Servlet where there are two important technologies: listeners and filters for fewer scenes listener used in web development there are some very special circumstances will use most of the web development where you can ignore its use we use the most is probably the listener to create and destroy ServletContext listener, ServletContext global object is the entire web application, and it is the life cycle of Web applications bundled together, so this listener to use the global Web application initialize and destroy information, for example the initialization operation of the spring container. More interesting is a filter, there interceptor struts2 where their role is to intercept the same request, since the unique features struts2 interceptor is using interceptors struts2 more smoothly than in the natural filters, in fact, the interceptor used technology more advanced than the filter, because the interceptor uses reflective technology, and therefore a greater interceptor to intercept the plane, the ability to control more requests, it can complete the task will be more colorful.

 

  In my first contact with struts2 in gxpt system, I was told that a purpose designed just want to shield struts in the control layer in the operation request and response objects, as the son of two http protocols will cause confusion in web development ideas but I often unconsciously use these two objects in the actual development actually. struts2 was used too much reflection, particularly the use of annotations to do the configuration, the efficiency is reflected in the java is very low, the direct use servlet will be able to enhance the efficiency of a web application. In fact, this fall is difficult to do, because I was not in the servlet flexible use spring technology.

 

 

  java spring technology can be said to be the most important companies to develop technology, but really understand the role and significance of the spring really is a troublesome thing, many people are actually stay in the spring to understand the use phase (eg: declarative transaction is easy to use, etc.), today's technology environment in the spring can be described as spectacular, spring has been all-inclusive, it's as much as fully as much as its content source java language, while such a big box spring are built ioc aop technology and above, only in-depth understanding of these two techniques we can understand why the spring of this box can hold so many things.

 

  The first is the ioc, ioc technology first explanation is called inversion of control, it also has a dependency injection explanation is that these two names literally difficult to understand, but when you understand how it works you will find a description of how they accurate. Ioc essence of technology is to build object technology in other words, the technology into an object instance of a class in the java class is instantiated by the new keyword, every time a new class will have a new instance of the object, do depending on a waste, such a waste sometimes quite dangerous, because developers often only when we need a class can only ever produce one instance of the object this time you have to use singleton, also in design mode where you can also through generates an object factory mode, the used spring people see the above text to know, in the bean spring definition and contents of the above correspondence, scope produce single singleton object attributes, the prototype to produce a new object, can also bean factory ways to produce objects, the tool can be said of spring bean is to create objects. Object-oriented programming in object-oriented equivalent of a physical display of life, for example, we have a target role is to complete the operation to hunt, then hunt this object contains two internal auxiliary objects: humans gun, and the gun only gives the object hunt then hunting target to complete the hunting operation, but to build a gun person object is not easy as it looks, here with a gun, for example, we need to create a gun metal, machine tools need, need bullets, but the bullets and machine tools but also two new objects that a mutually nested interrelated, and everyone at Imagine if we build a gun in the java code of the object that is too complex and not a simple gun target but if we want to construct more complex aircraft carrier, the high cost of construction of this object is hard to imagine, how to remove such objects nested relationship of interdependence? spring provides a way, this way is the spring to provide a container, we define dependencies of each object in the xml file, complete the construction of the container objects, java code when we need to use an instance when you can from container acquisition, the building was taken over operation of the spring container objects, so it is called inversion of control, inversion of control, which means that originally belonged to build a java program function object handed over to take over the container, dependency injection is when you want to program when using an object, the container will inject it into the program, which is called dependency injection. In j ava development where we'd like to take a class offered, there are two ways, one is to construct a new class, a new class that inherits the class, another way to define a class sucked in the new class, on the establishment of an association between two classes then the relationship, spring ioc container of this association is to achieve a relationship (remember not the inheritance oh), then a class is to be given to the new class what way? Generally only two: one is the constructor, one is by way setXXX, which is spring containers used to inject two standard ways.

 

  Whether the above said inheritance, or the way they are actually associated with the development of tools to enhance the ability of the target object, there is a proxy mode in design mode, proxy mode will inherit and association modes used together, is the inheritance mode and proxy mode complex patterns of association, but the role of this complex problem is not that the object injection, but to find a nanny or a secretary for the specific operation objects, which heads II and the novel, like the number two heads of foreign representatives specific examples of objects, inlet and outlet instance of an object is through the number two heads, because of the specific instance of an object is the head of One, One heads to a dry event, so some transactional, repetitive tasks such as bubble tea, arranged for a car, take the trouble to do this kind of work is the head of the Dajia One, but the 2nd directorate for help, which is thought aop's, aop settlement procedures developed in transactional, and unrelated to the core business problems, but these problems for the realization of the business scene it is necessary, in the actual development in aop also save One way to code.

 

  Spring is the role of core technology is essentially a communication mechanism, spring always do our best for both sides to communicate information flow while reducing the cost of communication between the two sides, in reality institutions a good communicator is certainly the company's leadership, it will leadership and communication can mobilize the enthusiasm of various resources, good communication and leadership will do be tolerant to diversity, so that various people to follow him, so today is a big box spring, anything can be installed inside.

 

  Spring like banks, it can not directly create material wealth, but all resources should be carried out by circulating it, it can control the direction of economic development, world back to the program, spring role is being billed as a decoupling between programs, spring can reduce the coupling between the different modules, the reason is in program development in the communication of information between the different modules is accomplished by passing the object, and the object is to deliver smooth sound to build a good subject, and manage objects Construction of ways you can manage object is passed, which is the benefits of spring to bring the system architecture design.

Released six original articles · won praise 3 · Views 797

Guess you like

Origin blog.csdn.net/SmileLucki/article/details/105207606