Home Java javaTutorial What is the difference between struts2 and springMVC

What is the difference between struts2 and springMVC

Apr 17, 2020 am 09:43 AM
springmvc struts2

What is the difference between struts2 and springMVC

What is the difference between struts2 and springMVC?

1. Framework mechanism

1. Struts2 is implemented by Filter (StrutsPrepareAndExecuteFilter), and SpringMVC (DispatcherServlet) is implemented by Servlet.

2. Filter is initialized after the container is started; it crashes after the service is stopped, later than Servlet. Servlet is initialized when called, before Filter is called, and is destroyed after the service stops.

Recommended: "java learning"

2. Interception mechanism

1, Struts2

a, Struts2 framework is at the class level For interception, an Action will be created for each request. When integrating with Spring, the ActionBean injection scope of Struts2 is the prototype mode prototype (otherwise thread concurrency problems will occur), and then the request data is injected into the property through setters and getters.

b. In Struts2, an Action corresponds to a request and response context. When receiving parameters, it can be received through attributes. This shows that attribute parameters are shared by multiple methods.

c. A method of Action in Struts2 can correspond to a url, but its class attributes are shared by all methods, which makes it impossible to use annotations or other methods to identify its own method

2. SpringMVC

a. SpringMVC is a method-level interception. One method corresponds to a Request context, so the method is basically independent and has exclusive access to request and response data. Each method corresponds to a URL at the same time. The parameter passing is directly injected into the method, which is unique to the method. The processing results are returned to the framework through ModeMap.

b. During Spring integration, SpringMVC's Controller Bean defaults to singleton mode, so by default, only one Controller will be created for all requests. There should be no shared attributes, so it is thread-safe. If you want to change the default scope, you need to add @Scope annotation modification.

3. Performance

SpringMVC implements zero configuration. Due to SpringMVC’s method-based interception, singleton mode bean injection is loaded once. Struts2 is a class-level interception. Each request corresponds to a new Action of the instance, and all attribute value injections need to be loaded. Therefore, SpringMVC development efficiency and performance are higher than Struts2.

4. Interception mechanism

Struts2 has its own interception Interceptor mechanism. SpringMVC uses an independent Aop method, which causes the amount of configuration files of Struts2 to be larger than that of SpringMVC.

5. Configuration

spring MVC and Spring are seamless. The management and security of this project are also higher than Struts2 (of course Struts2 can also achieve the same effect as SpringMVC through different directory structures and related configurations, but there are many places that require xml configuration).

SpringMVC can be considered to have 100% zero configuration.

6. Design Ideas

Struts2 is more in line with OOP programming ideas, while SpringMVC is more cautious and expands on servlets.

7. Integration

SpringMVC integrates Ajax, which is very convenient to use. It can be implemented with just one annotation @ResponseBody, and then directly returns the response text, and the Struts2 interceptor integrates Ajax , when processing in Action, you generally have to install a plug-in or write your own code to integrate it, which is relatively inconvenient to use.

The above is the detailed content of What is the difference between struts2 and springMVC. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to view Struts2 historical vulnerabilities from a protection perspective How to view Struts2 historical vulnerabilities from a protection perspective May 13, 2023 pm 05:49 PM

1. Introduction The Struts2 vulnerability is a classic series of vulnerabilities. The root cause is that Struts2 introduces OGNL expressions to make the framework flexible and dynamic. With the patching of the overall framework improved, it will now be much more difficult to discover new Struts2 vulnerabilities than before. Judging from the actual situation, most users have already repaired historical high-risk vulnerabilities. Currently, when doing penetration testing, Struts2 vulnerabilities are mainly left to chance, or it will be more effective to attack unpatched systems after being exposed to the intranet. Online analysis articles mainly analyze these Struts2 vulnerabilities from the perspective of attack and exploitation. As the new H3C offense and defense team, part of our job is to maintain the rule base of ips products. Today we will review this system.

Comparison and difference analysis between SpringBoot and SpringMVC Comparison and difference analysis between SpringBoot and SpringMVC Dec 29, 2023 am 11:02 AM

SpringBoot and SpringMVC are both commonly used frameworks in Java development, but there are some obvious differences between them. This article will explore the features and uses of these two frameworks and compare their differences. First, let's learn about SpringBoot. SpringBoot was developed by the Pivotal team to simplify the creation and deployment of applications based on the Spring framework. It provides a fast, lightweight way to build stand-alone, executable

What is the principle of Struts2 framework What is the principle of Struts2 framework Jan 04, 2024 pm 01:55 PM

The principle of the Struts2 framework: 1. The interceptor parses the request path; 2. Finds the complete class name of the Action; 3. Creates the Action object; 4. Execute the Action method; 5. Returns the result; 6. View parsing. Its principle is based on the interceptor mechanism, which completely separates the business logic controller from the Servlet API, improving the reusability and maintainability of the code. By using the reflection mechanism, the Struts2 framework can flexibly create and manage Action objects to process requests and responses.

What are the differences between SpringBoot and SpringMVC? What are the differences between SpringBoot and SpringMVC? Dec 29, 2023 am 10:46 AM

What is the difference between SpringBoot and SpringMVC? SpringBoot and SpringMVC are two very popular Java development frameworks for building web applications. Although they are often used separately, the differences between them are obvious. First of all, SpringBoot can be regarded as an extension or enhanced version of the Spring framework. It is designed to simplify the initialization and configuration process of Spring applications to help developers

How does the Struts2 S2-059 remote code execution vulnerability reproduce? How does the Struts2 S2-059 remote code execution vulnerability reproduce? May 23, 2023 pm 10:37 PM

0x00 Introduction Struts2 is a very powerful JavaWeb open source framework launched by the Apache software organization, which is essentially equivalent to a servlet. Struts2 is based on MVC architecture and has a clear framework structure. It is usually used as a controller to establish data interaction between models and views, and is used to create enterprise-level Java web applications. It utilizes and extends the JavaServletAPI and encourages developers to adopt the MVC architecture. Struts2 takes the excellent design ideas of WebWork as the core, absorbs some advantages of the Struts framework, and provides a neater Web application framework implemented in the MVC design pattern. 0x01 vulnerability

Struts2 vulnerability S2-001 example analysis Struts2 vulnerability S2-001 example analysis May 15, 2023 pm 03:58 PM

Vulhub vulnerability series: struts2 vulnerability S2-0011. Vulnerability description: struts2 vulnerability S2-001 is when the user submits form data and verification fails, the server uses OGNL expression to parse the parameter value previously submitted by the user, %{value} and refills the corresponding form data. For example, in a registration or login page. If the submission fails, the server will usually default to returning the previously submitted data. Since the server uses %{value} to perform OGNL expression parsing on the submitted data, the server can directly send the payload to execute the command. 2. Vulhub vulnerability exploitation: Using vulhub to reproduce vulnerabilities can save the environment construction process, which is very convenient. vu

Struts2-057 two versions of RCE vulnerability example analysis Struts2-057 two versions of RCE vulnerability example analysis May 15, 2023 pm 06:46 PM

Foreword On August 22, 2018, Apache Strust2 released the latest security bulletin. Apache Struts2 has a high-risk remote code execution vulnerability (S2-057/CVE-2018-11776). The vulnerability was discovered by ManYueMo, a security researcher from the SemmleSecurityResearch team. This vulnerability is due to the fact that when using the namespace function to define XML configuration in the Struts2 development framework, the namespace value is not set and is not set in the upper-layer action configuration (ActionConfiguration) or a wildcard namespace is used, which may lead to remote code execution. In the same way, u

Example analysis of Struts2 framework site risks Example analysis of Struts2 framework site risks May 30, 2023 pm 12:32 PM

1. Overview Struts is an open source project sponsored by the Apache Software Foundation (ASF). It started as a sub-project within the Jakarta project and later became a top-level project of ASF. By using JavaServlet/JSP technology, it implements the application framework [WebFramework] based on the Model-View-Controller [MVC] design pattern of JavaEE Web applications. It is a classic product in the MVC classic design pattern. In the early days of the development of JavaEE web applications, in addition to using Servlet technology, HTM was generally used in the source code of JavaServerPages (JSP).

See all articles