This article mainly introduces the difference between struts2 and spring MVC in Java. It is very good and has reference value. Friends who need it can refer to it
1. Struts2 is a class-level interception. One class corresponds to A request context, SpringMVC is a method-level interception, a method corresponds to a request context, and the method also corresponds to a url, so from the architecture itself, SpringMVC can easily implement restful url, while the struts2 architecture is difficult to implement because 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 methods are basically independent and have exclusive access to request response data. The request data is obtained through parameters, and the processing results are returned to the framework through ModelMap. No variables are shared between methods.
3. Since Struts2 needs to encapsulate each request, encapsulate the variables of the servlet life cycle such as request and session into Maps for use by each Action and ensure thread safety, so in principle, It consumes more memory.
4. In terms of interceptor implementation mechanism, Struts2 has its own interceptor mechanism, while SpringMVC uses an independent AOP method. This results in the amount of configuration files of Struts2 being larger than that of SpringMVC.
5. The entrance of SpringMVC is servlet, while Struts2 is filter (it should be pointed out here that filter and servlet are different. In the past, filter was considered to be a special type of servlet), which leads to different mechanisms of the two. , here involves the difference between servlet and filter.
6. 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. The Struts2 interceptor integrates Ajax, which is generally required when processing in Action. Installing plug-ins or writing your own code to integrate them is relatively inconvenient to use.
7. SpringMVC verification supports JSR303, which is relatively more flexible and convenient to handle, while Struts2 verification is more cumbersome and feels too confusing.
8. 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).
9. In terms of design ideas, Struts2 is more in line with OOP programming ideas, while SpringMVC is more cautious and expands on servlets.
10. SpringMVC performance is higher than Struts2.
11. SpringMVC can be considered to have 100% zero configuration.
The above is the detailed content of Compare the usage differences between struts2 and spring MVC in Java. For more information, please follow other related articles on the PHP Chinese website!

一、前言Struts2漏洞是一个经典的漏洞系列,根源在于Struts2引入了OGNL表达式使得框架具有灵活的动态性。随着整体框架的补丁完善,现在想挖掘新的Struts2漏洞会比以前困难很多,从实际了解的情况来看,大部分用户早就修复了历史的高危漏洞。目前在做渗透测试时,Struts2漏洞主要也是碰碰运气,或者是打到内网之后用来攻击没打补丁的系统会比较有效。网上的分析文章主要从攻击利用的角度来分析这些Struts2漏洞。作为新华三攻防团队,我们的一部分工作是维护ips产品的规则库,今天回顾一下这个系

java实现定时任务Jdk自带的库中,有两种方式可以实现定时任务,一种是Timer,另一种是ScheduledThreadPoolExecutor。Timer+TimerTask创建一个Timer就创建了一个线程,可以用来调度TimerTask任务Timer有四个构造方法,可以指定Timer线程的名字以及是否设置为为守护线程。默认名字Timer-编号,默认不是守护线程。主要有三个比较重要的方法:cancel():终止任务调度,取消当前调度的所有任务,正在运行的任务不受影响purge():从任务队

一、@RequestParam注解对应的axios传参方法以下面的这段Springjava代码为例,接口使用POST协议,需要接受的参数分别是tsCode、indexCols、table。针对这个Spring的HTTP接口,axios该如何传参?有几种方法?我们来一一介绍。@PostMapping("/line")publicList

Struts2框架的原理:1、拦截器解析请求路径;2、查找Action的完整类名;3、创建Action对象;4、执行Action方法;5、返回结果;6、视图解析。它原理基于拦截器的机制,使得业务逻辑控制器与Servlet API完全脱离开,提高了代码的可重用性和可维护性。通过使用反射机制,Struts2框架可以灵活地创建和管理Action对象,实现请求与响应的处理。

SpringBoot和SpringCloud都是SpringFramework的扩展,它们可以帮助开发人员更快地构建和部署微服务应用程序,但它们各自有不同的用途和功能。SpringBoot是一个快速构建Java应用的框架,使得开发人员可以更快地创建和部署基于Spring的应用程序。它提供了一个简单、易于理解的方式来构建独立的、可执行的Spring应用

随着技术的更新迭代,Java5.0开始支持注解。而作为java中的领军框架spring,自从更新了2.5版本之后也开始慢慢舍弃xml配置,更多使用注解来控制spring框架。

1.Spring项目的创建1.1创建Maven项目第一步,创建Maven项目,Spring也是基于Maven的。1.2添加spring依赖第二步,在Maven项目中添加Spring的支持(spring-context,spring-beans)在pom.xml文件添加依赖项。org.springframeworkspring-context5.2.3.RELEASEorg.springframeworkspring-beans5.2.3.RELEASE刷新等待加载完成。1.3创建启动类第三步,创

作为一名Java开发者,学习和使用Spring框架已经是一项必不可少的技能。而随着云计算和微服务的盛行,学习和使用SpringCloud成为了另一个必须要掌握的技能。SpringCloud是一个基于SpringBoot的用于快速构建分布式系统的开发工具集。它为开发者提供了一系列的组件,包括服务注册与发现、配置中心、负载均衡和断路器等,使得开发者在构建微


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools
