Difference between struts1.2 and struts2.0?
Answers were Sorted based on User's Feedback
Answer / sunil kumar suman
1. Servlet Dependency:
Actions in Struts1 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. 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 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 an execute signature can
be used as an Struts 2 Action object.
3. Validation
Struts1 and Struts 2 both supports the manual validation
via a validate method.
Struts1 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 Struts1, 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 Struts1 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 Struts1 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
Struts1. 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
Struts1 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 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
Struts1 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, Struts1 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, Struts1 ActionForm properties are all Strings.
Struts1 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
Struts1 supports separate Request Processor (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.
| Is This Answer Correct ? | 53 Yes | 4 No |
Answer / sunil kumar suman
Feature Struts 1 Struts 2
Action classes Struts 1 requires Action classes to extend
an abstract base class. A common problem in Struts 1 is
programming to abstract classes instead of interfaces. An
Struts 2 Action may implement an Action interface, along
with other interfaces to enable optional and custom
services. 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.
Threading Model Struts 1 Actions are singletons and must be
thread-safe since there will 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. Action
resources must be thread-safe or synchronized. 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.)
Servlet Dependency Struts 1 Actions have dependencies on
the servlet API since the HttpServletRequest and
HttpServletResponse is passed to the execute method when an
Action is invoked. Struts 2 Actions are not coupled to a
container. Most often the servlet contexts are represented
as simple Maps, allowing Actions to be tested in isolation.
Struts 2 Actions can still access the original request and
response, if required. However, other architectural
elements reduce or eliminate the need to access the
HttpServetRequest or HttpServletResponse directly.
Testability A major hurdle to testing Struts 1 Actions is
that the execute method exposes the Servlet API. A third-
party extension, Struts TestCase, offers a set of mock
object for Struts 1. Struts 2 Actions can be tested by
instantiating the Action, setting properties, and invoking
methods. Dependency Injection support also makes testing
simpler.
Harvesting Input Struts 1 uses an ActionForm object to
capture input. Like Actions, all ActionForms must extend a
base class. Since other JavaBeans cannot be used as
ActionForms, developers often create redundant classes to
capture input. DynaBeans can used as an alternative to
creating conventional ActionForm classes, but, here too,
developers may be redescribing existing JavaBeans.
Struts 2 uses Action properties as input properties,
eliminating the need for a second input object. Input
properties may be rich object types which may have their
own properties. The 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. Rich object types, including business or domain
objects, can be used as input/output objects. The
ModelDriven feature simplifies taglb references to POJO
input objects.
Expression Language Struts 1 integrates with JSTL, so it
uses the JSTL EL. The EL has basic object graph traversal,
but relatively weak collection and indexed property
support. Struts 2 can use JSTL, but the framework also
supports a more powerful and flexible expression language
called "Object Graph Notation Language" (OGNL).
Binding values into views Struts 1 uses the standard JSP
mechanism for binding objects into the page context for
access. 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
reuse of views across a range of types which may have the
same property name but different property types.
Type Conversion Struts 1 ActionForm properties are usually
all Strings. Struts 1 uses Commons-Beanutils for type
conversion. Converters are per-class, and not configurable
per instance. Struts 2 uses OGNL for type conversion. The
framework includes converters for basic and common object
types and primitives.
Validation Struts 1 supports manual validation via a
validate method on the ActionForm, or through an extension
to the Commons Validator. Classes can have different
validation contexts for the same class, but cannot chain to
validations on sub-objects. 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.
Control Of Action Execution Struts 1 supports separate
Request Processors (lifecycles) for each module, but all
the Actions in the module must share the same lifecycle.
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.
| Is This Answer Correct ? | 35 Yes | 7 No |
Answer / kondu.mani@gmail.com
the main difference is in struts 1.x we use classes and
some degineatterns but in case of struts2.x we use
interfaces .its more flexible.but complex issues also we cna
handle easly ye useing interface concept.
Feature
Struts 1
Struts 2
Action classes
Struts1 extends the abstract base class by its action class.
The problem with struts1 is that it uses the abstract
classes rather than interfaces.
While in Struts 2, an Action class implements an Action
interface, along with other interfaces use optional and
custom services. Struts 2 provides a base ActionSupport
class that implements commonly used interfaces. Although an
Action interface is not necessary, any POJO object along
with an execute signature can be used as an Struts 2 Action
object.
Threading Model
Struts 1 Actions are singletons therefore they must be
thread-safe because only one instance of a class handles all
the requests for that Action. The singleton strategy
restricts to Struts 1 Actions and requires extra care to
make the action resources thread safe or synchronized while
developing an application.
Struts 2 doesn't have thread-safety issues as Action objects
are instantiated for each request. A servlet container
generates many throw-away objects per request, and one more
object does not impose a performance penalty or impact
garbage collection.
Servlet Dependency
Actions are dependent on the servlet API because
HttpServletRequest and HttpServletResponse is passed to the
execute method when an Action is invoked therefore Struts1.
Container does not treat the Struts 2 Actions as a couple.
Servlet contexts are typically represented as simple Maps
that allow Actions to be tested in isolation. Struts 2
Actions can still access the original request and response,
if required. While other architectural elements directly
reduce or eliminate the need to access the HttpServetRequest
or HttpServletResponse.
Testability
Struts1 application has a major problem while testing the
application because the execute method exposes the Servlet
API. Struts TestCase provides a set of mock object for Struts 1.
To test the Struts 2 Actions instantiate the Action, set the
properties, and invoking methods. Dependency Injection also
makes testing easier.
Harvesting Input
Struts 1 recieves an input by creating an ActionForm object.
Like the action classes, all ActionForms class must extend a
ActionForm base class. Other JavaBeans classes cannot be
used as ActionForms, while developers create redundant
classes to receive the input. DynaBeans is the best
alternative to create the conventional ActionForm classes.
Struts 2 requires Action properties as input properties that
eliminates the need of a second input object. These Input
properties may be rich object types, since they may have
their own properties. Developer can access the Action
properties from the web page using the taglibs. Struts 2
also supports the ActionForm pattern, POJO form objects and
POJO Actions as well.
Expression Language
Struts1 integrates with JSTL, so it uses the JSTL EL. The EL
has basic object graph traversal, but relatively weak
collection and indexed property support.
Struts 2 can use JSTL, but the framework also supports a
more powerful and flexible expression language called
"Object Graph Notation Language" (OGNL).
Binding values into views
Struts 1 binds objects into the page context by using the
standard JSP mechanism.
Struts 2 uses a ValueStack technology to make the values
accessible to the taglibs without coupling the view to the
object to which it is rendering. The ValueStack strategy
enables us to reuse views across a range of types, having
same property name but different property types.
Type Conversion
Struts 1 ActionForm properties are almost in the form of
Strings. Commons-Beanutils are used by used by Struts 1 for
type conversion. Converters are per-class, which are not
configurable per instance.
Struts 2 uses OGNL for type conversion and converters to
convert Basic and common object types and primitives as well.
Validation
Struts 1 uses manual validation that is done via a validate
method on the ActionForm, or by using an extension to the
Commons Validator. Classes can have different validation
contexts for the same class, while chaining to validations
on sub-objects is not allowed.
Struts 2 allows manual validation that is done by using the
validate method and the XWork Validation framework. The
Xwork Validation Framework allows chaining of validations
into sub-properties using the validations defined for the
properties class type and the validation context.
Control Of Action Execution
Each module in Struts 1 has a separate Request Processors
(lifecycles), while all the Actions in the module must share
the same lifecycle.
In Struts 2 different lifecycles are created on a per Action
basis via Interceptor Stacks. Custom stacks are created and
used with different Actions, as required.s
| Is This Answer Correct ? | 18 Yes | 4 No |
how to develop the submit and search operations in single jsp using struts?
What types of validations are available in xml based validation in struts2?
How does interceptor work in struts2?
What is interceptor? And life cycle methods of interceptor?
What is the purpose of @doublerangefieldvalidator annotation?
What is the differences between struts1 and struts2?
What configuration files are used in struts?
1.Which of the following can be performed using interceptors by the developer? 1. Provide pre-processing logic before invoking the action 2. Interact with the action and set the request parameter on the action 3. Provide post-processing logic after invoking the action 4. Modify the result 1, 2, 3 2, 3, 4 1, 2, 4 1, 2, 3, 4 2.Interceptors can be used for which of the following tasks? 1. Checking security and bottleneck 2. Tracing the log 3. Validating user input 4. Uploading file 1, 2, 3 2, 3, 4 1, 2, 4 1, 2, 3, 4 3.The ValueStack is made up of which of the following objects? 1. Temporary Objects 2. Model Object 3. Action Object 4. Permanent Object 1, 2, 3 2, 3, 4 1, 2, 4 1, 2, 3, 4 4.Which of the following statements are correct? Apache Struts is a Java based framework that separates the application logic from the presentation layer. Action is based on pull-MVC framework which means that the data to be displayed is pulled from the action class which is a POJO class acting as a model in the Web application. OGNL is a powerful expression language that allows you to refer and manipulate the data present on the ValueStack. Declarative architecture enables you to integrate the different components present in the Web application either using XML files or Annotations. 5.Which of the following are the examples of helpers? 1. Action Interface 2. ActionSupport Class 3. ActionImplement Interface 1, 2 2, 3 1, 3 1, 2, 3 6.The Struts 2 filter performs which of the following tasks? 1. Installation of the Action class 2. Execution of the method specified in the configuration file 3. Reading of the control string 1, 2 2, 3 1, 3 1, 2, 3 7.Which of the following value for the debug parameter displays an OGNL console to test OGNL expressions against the value stack? xml console command All of the above. 8.Which of the following are correct statements? The execute () method of the action class defines business logic implementations. ActionSupport class adds useful utilities to the class that extends it. Set of Interceptors are grouped into a stack known as Interceptor Stack. All of the above. 9.Which of the following annotation helps to set the path of the action URL? It is placed before the action class and it applies to all actions defined in the class, even if the fully qualified URLs are not supplied. @Namespace @Result @Results @ParentPackage 10.Which of the following statements are correct related to OGNL and Annotations? OGNL is an expression and binding language that is used for getting and setting the properties of the Java objects. Annotations acts as an alternative to HTML and Java properties configuration file. Action Annotations are available when the framework scans the classpath for action classes. Lifecycle callback annotations are invoked at any time during the processing of an action. 11.Which of the following are the features of the new unified Expression Language? Deferred evaluation of expression Support expressions that can set values and invoke methods Provides a pluggable API for resolving expressions All of the above. 12.By introducing the new feature by JSF, improvements have been made in which of the following areas? Set of standard converter messages Addition of requiredMessage, converterMessage, and validatorMessage attribute for input components. Displaying the error message using the input component name with the help of label attribute added to the input components All of the above. 13.Which of the following statements are correct about the 'label' attribute? In JSF 2.1, the label attribute have been introduced with the input components. The label attribute can accept literal or value expressions. The Literal or value expressions accepted by label attribute is prefixed before the components error message. All of the above. 14.Which of the following statements are correct? EL allows developers to use simple expressions to dynamically access data from JavaBeans components. EL supports only deferred evaluation. A value expression can either yield a value or set a value and can be used for both read and write. In immediate evaluation, the expression is evaluated immediately. 15.Which of the following statements are correct? Method expression invokes as arbitrary private method of an arbitrary object by passing a specified set of parameters and returning results from the calling method. JSTL is a part of Java EE 5 platform. JSF 1.2 includes a set of messages for standard converters. The requiredMessage, converterMessage, or the validatorMessage attribute of the input components are used to provide custom error messages.
Explain the core end goal while using java struts?
How to add ms-word file in struts at the same time how to add images
advantages& 5 disadvantages of MVC architecture
Which design pattern is implemented by Struts2 interceptors?