In the following section, we are going to compare the various features between the two frameworks. Struts 2.x is very simple in comparison to the struts 1.x , few of its excelling features are:
1. Servlet Dependency:
Actions in Struts 1 have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse objects are passed to the execute method when an Action is invoked but in case of Struts 2 , Actions are not container dependent because they are made simple POJOs(由于Struts2的Action是简单的POJOs,所以Action不依赖于容器。). In struts 2, the servlet contexts are represented as simple Maps which allows actions to be tested in isolation. Struts 2 Actions can access the original request and response, if required. However, other architectural elements reduce or eliminate the need to access the HttpServetRequest or HttpServletResponse directly.
2. Action classes
Programming the abstract classes instead of interfaces is one of design issues of struts1 framework that has been resolved in the struts 2 framework. (在Struts1框架设计中面向抽象类编程代替接口这一问题在Struts2中已经被解决。)
Struts 1 Action classes needs to extend framework dependent abstract base class. But in case of Struts 2 Action class may or may not implement interfaces to enable optional and custom services. In case of Struts 2 , Actions are not container dependent because they are made simple POJOs. Struts 2 provides a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is not required. Any POJO object with a execute signature can be used as an Struts 2 Action object.
3. Validation
Struts 1 and Struts 2 both supports the manual validation via a validate method.
Struts 1 uses validate method on the ActionForm, or validates through an extension to the Commons Validator. However, Struts 2 supports manual validation via the validate method and the XWork Validation framework. The Xwork Validation Framework supports chaining validation into sub-properties using the validations defined for the properties class type and the validation context.
4. Threading Model
In Struts 1, Action resources must be thread-safe or synchronized. So Actions are singletons and thread-safe, there should only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts 1 Actions and requires extra care to develop. However in case of Struts 2, Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.)
5. Testability
Testing Struts1 applications are a bit complex. A major hurdle to test Struts 1 Actions is that the execute method because it exposes the Servlet API. A third-party extension, Struts TestCase, offers a set of mock object for Struts 1. But the Struts 2 Actions can be tested by instantiating the Action, setting properties, and invoking methods. Dependency Injection support also makes testing simpler. Actions in struts2 are simple POJOs and are framework independent, hence testability is quite easy in struts2.
6. Harvesting Input
Struts 1 uses an ActionForm object to capture input. And all ActionForms needs to extend a framework dependent base class. JavaBeans cannot be used as ActionForms, so the developers have to create redundant classes to capture input.
However the Struts 2 uses Action properties (as input properties independent of underlying framework) that eliminates the need for a second input object, hence reduces redundancy. Additionally in struts2, Action properties can be accessed from the web page via the taglibs. Struts 2 also supports the ActionForm pattern, as well as POJO form objects and POJO Actions. Even rich object types, including business or domain objects, can be used as input/output objects.
7. Expression Language
Struts 1 integrates with JSTL, so it uses the JSTL-EL. The struts1 EL has basic object graph traversal, but relatively weak collection and indexed property support. Struts 2 can also use JSTL, however it supports a more powerful and flexible expression language called "Object Graph Notation Language" (OGNL).
8. Binding values into views
In the view section, Struts 1 uses the standard JSP mechanism to bind objects(processed from the model section) into the page context to access . However Struts 2 uses a "ValueStack" technology so that the taglibs can access values without coupling your view to the object type it is rendering. The ValueStack strategy allows the reuse of views across a range of types which may have the same property name but different property types.
9. Type Conversion
usually , Struts 1 ActionForm properties are all Strings. Struts 1 uses Commons-Beanutils for type conversion. These type converters are per-class, and not configurable per instance. However Struts 2 uses OGNL for type conversion. The framework includes converters for basic and common object types and primitives.
10. Control Of Action Execution
Struts 1 supports separate Request Processors (lifecycles) for each module, but all the Actions in a module must share the same lifecycle. However Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions, as needed.
分享到:
相关推荐
Struts1.x与Struts2.x是两种非常流行的Java Web应用程序框架,它们都由Apache软件基金会开发,旨在简化MVC(Model-View-Controller)架构的实现。然而,两者在设计哲学、功能特性以及实现方式上存在显著差异。以下是...
### Struts1.x与Struts2.x的主要区别 在深入探讨Struts1.x与Struts2.x的区别之前,我们先来了解一下这两个框架的基本背景。Apache Struts是用于构建企业级Web应用程序的开源框架,它提供了MVC(模型-视图-控制器)...
虽然现在Struts1.x已经被Struts2等更新的框架所取代,但它的基础思想和设计模式仍然是Java Web开发中的重要参考。对于想要了解Web开发历史或深入理解MVC框架的开发者来说,学习Struts1.x仍然具有一定的价值。
### Struts1.x 技术课程讲解 #### 一、Struts1.x 概述 **Struts1.x** 是一款基于 Java Servlet 和 JSP 技术的企业级 Web 应用开发框架,它实现了 Model-View-Controller (MVC) 设计模式。此框架旨在简化 Web 应用...
2. **Action类**:每个HTTP请求都对应一个Action类,这是Struts1.x的核心组件。Action类处理用户请求,执行相应的业务逻辑,并通过ActionForward决定响应的视图。 3. **配置文件**:主要包括struts-config.xml,这...
Struts 2.x权威指南(第3版)
然而,随着时间的推移,Struts 1.x 因为其局限性和安全问题,逐渐被Struts 2 和其他现代框架如Spring MVC、Play Framework等取代。尽管如此,了解 Struts 1.x 的基础知识对于理解Java Web开发的历史和演变仍然非常有...
Struts1.x是一款经典的Java Web框架,由Apache软件基金会开发并维护。它是MVC(Model-View-Controller)设计模式的实现,极大地简化了Java Web应用程序的开发过程。本资源集合包含了所有最新的Struts1.x项目应用,为...
Struts1.x是一个经典的Java Web开发框架,它遵循Model-View-Controller(MVC)设计模式,用于构建可维护性和可扩展性高的企业级应用程序。在这个"Struts1.x_Project.zip"压缩包中,我们可以看到一个使用Struts1.x...
【Struts1.x入门教程】 Struts1.x是Apache Jakarta项目的一个重要组成部分,它是一个用于构建企业级Web应用程序的开源MVC框架。该框架的主要目标是简化JavaServer Pages(JSP)、Servlet和标签库的使用,同时提升...
**Struts2.x与Struts1.x对比**:相较于Struts1.x,Struts2.x具有更多的优势,如不再强制要求ActionForm,配置文件更简洁,处理流程更加清晰。具体而言,请求首先被过滤器捕获,然后根据`struts.xml`文件的配置调用...
Struts1.x是一个经典的Java Web框架,它在20世纪末至21世纪初被广泛使用,用于构建基于MVC(Model-View-Controller)架构的Web应用。本示例将探讨如何使用Struts1.x实现一个简单的登录功能。首先,我们需要理解...
Struts1.x是一个经典的Java Web框架,用于构建MVC(模型-视图-控制器)架构的应用程序。在国际化(i18n)方面,Struts1提供了强大的支持,使得应用程序可以适应不同语言和地区的用户需求。以下是关于Struts1.x国际化...
Struts 1.x 是一个经典的Java Web开发框架,由Apache软件基金会开发,它极大地...不过需要注意的是,Struts 1.x已经较为老旧,目前更推荐使用Struts 2或者Spring MVC等更新的框架,它们提供了更多的特性和更好的性能。
freemarker与struts 1.x 结合,生成html 在http://blog.csdn.net/chen1255 的web中有详细描述关于freemarker与struts1.x的结合
本篇文章将深入探讨Struts1.x和Struts2.x在向Action中填充JSP参数的原理。 Struts1.x的工作原理: Struts1的核心是ActionServlet,它是一个实现了Servlet接口的控制器。当用户发起HTTP请求时,请求会被Dispatcher...
Struts1.x是一个非常经典的Java Web开发框架,它在过去的许多年里被广泛使用。文件上传功能是Web应用中常见的需求之一,特别是在处理用户需要提交多个文件的场景下。Struts1.x提供了处理多文件上传的功能,使得...
标题"Struts2.X+Hibernate3.X+Spring2.5 整合"指的是将这三个框架的特定版本(Struts2.X,Hibernate3.X,Spring2.5)集成到同一个项目中,实现高效的企业级应用开发。这种整合能够充分利用各个框架的优势,使开发者...
Struts1.x、Hibernate 和 MySQL 是构建Web应用程序的三个关键组件,它们在电子商务系统中扮演着重要的角色。这里我们将深入探讨这些技术以及如何在在线购物车系统中整合它们。 **Struts1.x** 是一个开源的Java框架...