Thursday, February 23, 2012

Struts2 why more powerful than Struts1. Struts2 Vs Struts1 . Compare between Struts1 and Struts2

STRUTS2 = STRUTS1 + Interceptor (=XWork) + OGNL - FormBean

1. Easy web.xml






No struts-config.xml inside WEB-INF folder.

2. Easy Action Class.

public class MyAction extends Action {
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
            throws Exception {
        // do the work
        return (mapping.findForward("success"));

All actions have to be thread-safe, as only a single action instance is created.
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.
Because the actions have to be thread-safe, all the objects that may be needed in the processing of the action are passed in the method signature.

Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues.
public class MyAction {
   public String execute() throws Exception {
        // do the work
        return "success";

Here no need to extends other class and no need to pass every thing in execute method.

If you want to use any session or request ro response object then use xxxxAware, example:
public class MyAction implements ServletRequestAware {
   private HttpServletRequest request;
   public void setServletRequest(HttpServletRequest request) {
        this.request = request;
   public String execute() throws Exception {
        // do the work using the request
        return Action.SUCCESS;

3. No Action From

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.

All data of ActionForm will do here in action class, so need to create one more class.The Action properties can be accessed from the web page via the taglibs.

4. Advanced 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).

5. Easy Validation

Struts 1 supports manual validation via a validate method on the ActionForm, or through an extension to the Commons Validator.

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.

Content Source.
Another Source.


Binod Suman


  1. HI Suman,

    Thanks for your tutorial, I am working on struts1.2 web application , i would like to call Ajax , if you have any sample program struts with ajax please share it.
    once agin thanks in advance.

  2. Nice explanation thank you..


You can put your comments here (Either feedback or your Question related to blog)