Вы находитесь на странице: 1из 4

Struts1 vs Struts2 Page 1 of 4

Feature Struts 1 Struts 2

While in Struts 2, an
Action class
implements an Action
interface, along with
other interfaces use
optional and custom
Struts1 extends the
services. Struts 2
abstract base class by
provides a base
its action class. The
Action ActionSupport class
problem with struts1
classes that implements
is that it uses the
commonly used
abstract classes rather
interfaces. Although an
than interfaces.
Action interface is not
necessary, any POJO
object along with an
execute signature can
be used as an Struts 2
Action object.

Struts 1 Actions are


singletons therefore
Struts 2 doesn't have
they must be thread-
thread-safety issues as
safe because only one
Action objects are
instance of a class
instantiated for each
handles all the
request. A servlet
requests for that
container generates
Threading Action. The singleton
many throw-away
Model strategy restricts to
objects per request, and
Struts 1 Actions and
one more object does
requires extra care to
not impose a
make the action
performance penalty or
resources thread safe
impact garbage
or synchronized while
collection.
developing an
application.

http://www.roseindia.net/struts/struts1-vs-struts2.shtml 10/31/2010
Struts1 vs Struts2 Page 2 of 4

Container does not


treat the Struts 2
Actions as a couple.
Servlet contexts are
Actions are dependent typically represented as
on the servlet API simple Maps that allow
because Actions to be tested in
HttpServletRequest isolation. Struts 2
Servlet and Actions can still access
Dependency HttpServletResponse the original request and
is passed to the response, if required.
execute method when While other
an Action is invoked architectural elements
therefore Struts1. directly reduce or
eliminate the need to
access the
HttpServetRequest or
HttpServletResponse.

Struts1 application
To test the Struts 2
has a major problem
Actions instantiate the
while testing the
Action, set the
application because
properties, and
Testability the execute method
invoking methods.
exposes the Servlet
Dependency Injection
API. Struts TestCase
also makes testing
provides a set of mock
easier.
object for Struts 1.

Struts 1 recieves an Struts 2 requires Action


input by creating an properties as input
ActionForm object. properties that
Like the action eliminates the need of a
classes, all second input object.
ActionForms class These Input properties
must extend a may be rich object
ActionForm base types, since they may

http://www.roseindia.net/struts/struts1-vs-struts2.shtml 10/31/2010
Struts1 vs Struts2 Page 3 of 4

class. Other have their own


JavaBeans classes properties. Developer
cannot be used as can access the Action
ActionForms, while properties from the
developers create web page using the
Harvesting redundant classes to taglibs. Struts 2 also
Input receive the input. supports the
DynaBeans is the best ActionForm pattern,
alternative to create POJO form objects and
the conventional POJO Actions as well.
ActionForm classes.

Struts1 integrates with Struts 2 can use JSTL,


JSTL, so it uses the but the framework also
JSTL EL. The EL has supports a more
Expression basic object graph powerful and flexible
Language traversal, but expression language
relatively weak called "Object Graph
collection and indexed Notation
property support. Language" (OGNL).

Struts 2 uses a
ValueStack technology
to make the values
accessible to the taglibs
without coupling the
Struts 1 binds objects view to the object to
Binding
into the page context which it is rendering.
values into
by using the standard The ValueStack
views
JSP mechanism. strategy enables us to
reuse views across a
range of types, having
same property name
but different property
types.

Struts 1 ActionForm
properties are almost

http://www.roseindia.net/struts/struts1-vs-struts2.shtml 10/31/2010
Struts1 vs Struts2 Page 4 of 4

in the form of Strings.


Commons-Beanutils
Struts 2 uses OGNL for
are used by used by
type conversion and
Struts 1 for type
Type converters to convert
conversion.
Conversion Basic and common
Converters are per-
object types and
class, which are not
primitives as well.
configurable per
instance.

Struts 2 allows manual


Struts 1 uses manual
validation that is done
validation that is done
by using the validate
via a validate method
method and the XWork
on the ActionForm, or
Validation framework.
by using an extension
The Xwork Validation
to the Commons
Framework allows
Validation Validator. Classes can
chaining of validations
have different
into sub-properties
validation contexts for
using the validations
the same class, while
defined for the
chaining to
properties class type
validations on sub-
and the validation
objects is not allowed.
context.

In Struts 2 different
Each module in Struts
lifecycles are created
1 has a separate
on a per Action basis
Control Of Request Processors
via Interceptor Stacks.
Action (lifecycles), while all
Custom stacks are
Execution the Actions in the
created and used with
module must share the
different Actions, as
same lifecycle.
required.s

http://www.roseindia.net/struts/struts1-vs-struts2.shtml 10/31/2010

Вам также может понравиться