Struts2 Highlights
Action implementation
Struts1: Action must extend from the Action class and has a high degree of coupling.
Struts2: Action can be an ordinary POJO (Plain Old Java Object) without inheriting any framework class, which reduces coupling.
Threading model
Struts1: Action is a single instance, multiple requests share the same instance, and there are thread safety issues.
Struts2: Each request creates a new Action instance, avoiding thread safety issues.
Servlet API dependencies
Struts1: Action relies on Servlet API (such as HttpServletRequest and HttpServletResponse), making the code difficult to test.
Struts2: Action does not depend on Servlet API, supports TDD (Test-Driven Development), and facilitates unit testing.
Struts2 features
Request parameter encapsulation
Struts1: Force the use of ActionForm objects to encapsulate request parameters.
Struts2: You can directly use the properties of POJO classes or Actions to encapsulate parameters, which is more flexible.
expression language
Struts1: Integrated EL (Expression Language), but has weak support for collections and indexes.
Struts2: Integrate OGNL (Object Graph Navigation Language) to support complex object graph navigation and property access.
View technology
Struts1: Use standard JSP as the view technology.
Struts2: Use ValueStack technology to support more flexible view data interaction.
Struts2 functions
type conversion
Struts1: The properties of ActionForm are usually of type String and need to be converted manually.
Struts2: Use OGNL to automatically perform type conversion and support more complex types (such as dates, collections, etc.).
Validation framework
Struts1: Support overriding the validate method or using the Validator framework.
Struts2: Supports overriding the validate method or using XWork's validation framework, making the configuration more flexible.
Action execution control
Struts1: All Actions in a module share the same life cycle.
Struts2: Create a different life cycle for each Action through the interceptor stack to support more fine-grained control.
Struts2 FAQ
Problem: Action class thread safety issue
Phenomenon: Multiple requests share Action instances, resulting in data confusion.
Reason: Struts2 creates a new instance for each request by default, but if configured in singleton mode (such as using Spring management), it may cause thread safety issues.
Solution:
Make sure the Action class is stateless (does not save data shared between requests).
Avoid configuring Action classes as singletons.
Struts2 update log:
Working day and night just so you can be happier
Mummy, Mummy, coax~all the bugs are gone!
Huajun editor recommends:
Believe me, as long as you use Struts2 and other JAVA program software, you can uninstall it and it will definitely meet all your needs. The editor has also carefully prepared for youJUDE,jarfix,Argo UML,Apache Tomcat 9,FreeJava















Your comment needs to be reviewed before it can be displayed