Struts framework over MVC mode

xiaoxiao2021-03-05  27

Keywords: Java J2EE MVC JSP Servlet MVC Struts

brief introduction:

The MVC design model has become a very popular design method. It is a software design method mode. It is proved by a large number of development and practice. Therefore, this article introduces the Struts framework software component that has implemented MVC mode. The framework discusses the advantages of this mode and how to invest in software development.

The content of this paper pays attention to theory and practice, comparing the technology used from multi-layer design to distributed software development, thereby cutting into the J2EE frame model exiting from Sun Company, and then discusses the technology related to it. , Including JSP, servlet, user-defined tag, etc., then discuss its advantages and defects, finalize the subject of the article, Struts framework, the framework changed the previous design method by implementing MVC design mode, making developing a set of J2EE The framework of the frame is very widely adaptable and extremely efficient.

Celebrity Quote:

If I look far than Cartel, it is because I stand on the shoulder of the giant people.

- Newton

People with rich knowledge and experience, more likely to produce new Lenovo and unique insights than people with only one knowledge and experience.

─ Taylor

introduction:

At present, the software development has entered an object-oriented, componentized, distributed application. The Java2 Enterprise Edition (J2EE) platform launched by SUN has become increasingly mature. Web's Web container in J2EE is a wide application. Components have also become the current development of web applications, the main tools and means. JavaServer Page (JSP) technology, almost every Java web application development must develop components.

The current web container is also a flowery, some free open source organizations have also been added to this sport. Tomcat, such as the Apache Software, is a very good Web container, which also promotes the development of Java's web application. With the maturity of Java's Web technology and the huge demand of the market. More and more developers have started using some development frameworks that have been recognized by developments. Now the idea of ​​software development is no longer "Do we want to use Software framework "but" what software development framework is used ".

Therefore, selecting an excellent development framework is required as a software developer. Jakarta-struts is a project of a set of development source code provided by the Apache software organization, which implements the model --- View --Controller (Model --- View --- Controller) MVC design mode. Its wide adaptability and high expansion capability plus a great improvement of production efficiency has become a gradual approval of Java's Web development.

Of course, as our developers are also a challenge, I have to understand these new ideas and understanding and accept the advantages of this development model, which requires our understanding and a large number of development practices.

Java web application introduction

Java web applications build applications by developing and deploying Java web components on a web container. Its technology is mainly Java Server Page and Servlet technology. In addition, developing a complete Java web app includes the following technologies:

l JavaBean component technology

l EJB component technology

l User custom tag library

l xml tag language

l J2EE related container

Figure 1 Technical structure of Java web application

Servlet controller component technology

Servlet is an important role in a typical web application that servlet is ideal for messaging between web pages. Because servlet is a component module dynamically loaded by a web container, it is not very suitable for user interface, When the web user issues a request, the servlet component can capture this request message via the servlet container so that it can call the model component to come out.

Figure 2 Servlet processing flow

When a client (such as a browser) issues a web request to the servlet container, the server accepts the corresponding servlet component after requesting the request to perform the corresponding program to complete this request, then the servlet component processing result is handed over to the servlet container, and then Reply to the client by the servlet container. This is also a typical web application execution process. Java's servlet technology provides a group of user programming interfaces to define related classes for developers.

The following comparison classes in the servlet API determine the process of service: l httpservlet: This class provides the ability to extend the user's extension, and users write a servlet component by inheritance. Mainly fill in the HTTP method (such as: DOPOST Doget) complete service .

l HTTPSERVLETREQUEST: This class provides the ability to accept the user request data, which is usually created by the web container in a client request service. Servlet can access the request data for the user when the user is accessed.

l httpservletResponse: This class is used to generate the corresponding result. This class is also created by the web container in the service.

l HttpSession: The same type of session tracking is handled.

l ServletContext: The Servlet container provides an environment for each web application module to hold the status of the application module. This set of status is shared information that all web components can be accessed in this module.

The above has a general introduction to the servlet component. If you want to know about the technology about servlet, you can access the site: http://www.servlet.com. There will be a detailed introduction there.

JSP component technology

JSP component technology is an extension of traditional static web pages (HTML) such that traditional static pages can join Java program code to provide program editing generating page effects. And the component technology also runs component technology on J2EE web containers .

The essence of JSP is actually the servlet component technology, just JSP technology more intended to use the representation interface of the user.

Figure 3 WEB container initially executes browser request processing JSP process

When the JSP page receives the user's request, first, the Web container will translate the JSP script file, then generate the servlet source code, compile the servlet source code to the Java's Bytecode generated a class file. Then handle the page with the execution process of the servlet. Process.

If the reader wants to learn more about JSP technology, you can get more help at http://java.sun.com/products/jsp/.

JavaBean components role in web applications

JavaBean is a Java class that meets specific specifications. It is defined in the JavaBean. We can usually encapsulate business to models and business process models in Javabean, and simply say that JavaBean is very suitable for models in web applications. The role of the component.

A set of tags supported by JavaBeans have been defined in the JSP standard tag. And define the lifecycle of the JavaBean object in the execution process. Includes Page, Request, Session, and Application Four ranges. And provide properties support for JavaBean access .

If you want to learn more about JavaBean, readers can refer to http://java.sun.com/products/javabeans site provides a very detailed introduction.

User definition label

User-defined labels in JSP provide developers with a good interface and feature extension capabilities. It supports users to define a corresponding service tag in the JSP page. Usually these tags are inherited from the Tagsupport class. And by rewrite the relevant method of the Tagsupport class To extend the function.

In Struts, the Struts framework defines a set of user tags. Its mainly include:

l bean tag, used to support JavaBean access

l HTML tags are used to support the creation and access of HTML interface elements.

l logic tags to support logic execution

l Neted tag and tiles tags are used to support interface representations

EJB component technology

ENTERPRISE JAVA BEAN referms a set of standard distributed object component technology. It is a server-side Java component of CORBA and RMI. EJB technology and JavaBean technology to handle business logic in business development. Their difference is that the EJB component is distributed The EJB container must be run. The JavaBean component is a component that runs in the calling party.

EJB defines a session bean that is basically used to handle business process logic and an entity bean used to maintain a business persistent state. And handle messages-based messages beans.

The EJB component is running the EJB container to maintain security, transactional, persistence, parallelism, and other services for EJB components. And provide support for development, deployment, operation and other environments. Readers can access http: // Java.sun.com/products/ejb/index.html learns these technologies.

XML markup language

The XML tag language can be used to define the user's own tag. XML is very extensive in the web service. If the SOAP protocol is defined by XML. XML can define very common and beneficial to the information structure processed by the application.

In the Struts framework, XML acts as a binder, which can be used to configure the compositional framework of each component in the Struts frame.

Readers can get more learning materials by visiting http://www3schools.com/xml/default.asp.

J2EE related container

Any distribution development in this stage is inseparable from the server. For web development, the web server is often used to process HTTP requests and reply, and provide security, transactionality, multitasking parallelism. Modern web container Programmable user interfaces are provided. The logical part of the application in distributed development is usually placed on the middleware server of the application. EJB container is such an intermediate server. The server provides support for the operating environment of the EJB component. And provide support for remote object call protocols such as RMI-IIOP, making it easy to develop EJB components here. Make more concern for developers to business logic issues.

The currently popular open source web server is mainly the Tomcat server of the Apache software. Tomcat is not only a very convenient Web server, but also a very convenient servlet / JSP container. The open source EJB container is more representative. JBoss it is Developed by JBoss software, its performance is stable and reliable, and has a very efficient execution speed.

MVC design pattern overview

In general, a computer program includes its input, processing, and output. The MVC design mode is independent of the input, processing, and output portions into independent program part. And combine it when the system is running, which makes the development coupling degree It is very low.

Figure 4 MVC design model

View, usually the interface of the user interaction in the software. It is used to represent data and submit a request for software to software.

Model, used to handle the business scope to be involved, mainly business data models and business logic models.

The controller used to accept the user's request and call the process in the model, and then select the corresponding view.

The MVC design mode is more useful in Java's web applications. The Jsp Model2 architecture is an implementation of the MVC mode of JSP, Servlet, and JavaBean technology.

Figure 5 JSP MODEL2 model

Struts framework overview

As software development is mature, software engineers have become gradually matured, we begin to design software framework structures, so we will work in order to develop during the development stage. And the development cycle of software development for modern software is required The more quickly, so if you want to develop a framework is not realistic. So we have to choose a mature software frame.

Struts is a good choice for Java's web development. The Struts framework is the implementation of the JSP MODEL2 model.

Figure 6 MVC framework implemented by Struts

View

The view is implemented through a set of JSP programs. These JSP programs cannot include business logic, nor cannot include the information of the model. The information of the model is passed through the controller. The ActionForm is also seen in the Struts part. It Other update views, and bridges of the view query model status.

2. Model

The model is the status of the program indicates that the state includes the state passed in the message, as well as the status of the shared state, or a persistent state. The flow of operation of these states is also included in the model. These models are business Overall operation procedure and data.

3. Controller

The controller portion is implemented by the ActionServlet and Action. ThectionsServlet is also an interface for the Struts framework for interacting with the web container. This class is the core component of the Struts framework .ActsRVlet inherits the httpservlet class. It plays the role of the central controller in the MVC model When a web container receives a customer request, the ActionServlet is delivered to the configuration information of the Struts-Config.xml file to handle the request. And pass the data during the request, which is passed through ActionForm .action itself. There is also no processing code for business logic. It is only responsible for calling the processing code of the business. The method of calling these codes is in the execute () method. This method will return an ActionForward object after calling the business process to select the corresponding view. Generally speaking, our Action must inherit the class directly or indirect. The Excecute () method is then overridden to complete our own processing message.

4.Struts configuration file struts-config.xml

The file is essentially a controller and a view of the adhesive, the controller can select the corresponding view, and the view can rely on the file by the corresponding controller to query the model. This file is an XML file. Each Action is used to map the information of the Action class in this configuration file.

From the demand analysis and design of the software

Implement a complete Struts-based web application

to sum up:

There are many technologies used in Java's web applications. Therefore, it is relatively complicated. Therefore, the technical aspects of developers responsible for developers will also be relatively, so we must consider personal expertise to allocate development work. We need to consider clearly in the design phase of the software. And the design model of MVC can be independent of the business data model and business processing model, which has developed a separate system component to facilitate a good maintenance in the development view phase. The consistency of the data is the relationship between the processing view and the model, the controller becomes the link, which makes the software project can be a systematic engineering.

The Struts framework has played this role in Java's web applications. This makes it possible to use the framework to complete the development project well, we can choose the appropriate model components, such as we can use JavaBean technology to complete business models and data models. The interface, and the database can act as a data model to maintain a persistent state of the business phase. JSP and Struts provide us with a set of tags that complement the page representation and page logic such that we have a rich view feature. And Struts provides an actionform for a view that the view can provide a good channel to provide a good channel that allows you to get data from the view from the view when processing the Action event. And the bridge between the two is the struts-config.xml file this XML file. You can configure the connection between the two. This has extremely flexibility and scalability between the interfaces. In Action, we have the ability to call and include the model components. This makes it very efficient and scalable.

The Struts framework has been applied by many software projects, so it is very reliable when it is suitable. Here, it is also desirable to make readers to have a sufficient understanding of the Struts framework through this question.

Reference:

<< proficient Struts MVC-based Java Web Design and Development >> Author: Sunweiqin

<< JSP 2.0 Technical Reference Manual >> Author: Lin Jie on Rincon Division

Inside >> << J2EE Author: (US) Joseph J.Bambara Paul R.Allen etc. Translator: Liu Kun, etc.

转载请注明原文地址:https://www.9cbs.com/read-33649.html

New Post(0)