O'Reilly logo

Jakarta Struts Cookbook by Bill Siggelkow

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

1.3. Migrating from Struts 1.0 to Struts 1.1

Problem

You need to migrate a Struts 1.0-based application to Struts 1.1.

Solution

Replace the Struts 1.0 JAR files, tag library descriptor (TLD) files, and XML DTD files with the corresponding files from Struts 1.1. If you have JSP pages that use the absolute URI from the Struts tag libraries, you'll need to change these. Recompile your application using the new libraries and address any compilation errors.

Finally, you'll want to modify your code that is using deprecated APIs to use the new Struts 1.1 APIs.

Discussion

While Struts 1.1 was a significant change to Struts 1.0, functionally speaking, applications based on Struts 1.0 can be migrated without much difficulty by replacing the Struts 1.0 JARs and TLDs with the corresponding files for Struts 1.1. You will need to change your use of the tag library URIs, as they have changed in Struts 1.1; this generally means changing your web.xml deployment descriptor. If you use the absolute URIs in your JSP pages, these values will need to be changed as well. Table 1-3 shows the changes to the tab library URIs.

Table 1-3. Struts tag library URIs

Struts 1.0.2 Taglib URI

Struts 1.1 Taglib URI

http://jakarta.apache.org/struts/tags-bean-1.0.2

http://jakarta.apache.org/struts/tags-bean

http://jakarta.apache.org/struts/tags-html-1.0.2

http://jakarta.apache.org/struts/tags-html

http://jakarta.apache.org/struts/tags-logic-1.0.2

http://jakarta.apache.org/struts/tags-logic

http://jakarta.apache.org/struts/tags-template-1.0.2

http://jakarta.apache.org/struts/tags-template

Not Available with Struts 1.0.2

http://jakarta.apache.org/struts/tags-tiles

Not Available with Struts 1.0.2

http://jakarta.apache.org/struts/tags-nested

The most significant changes in Struts 1.1 were the Struts ActionServlet (org.apache.action.ActionServlet) and the Struts Action class (org.apache.struts.Action). Struts 1.1 introduced the concept of the RequestProcessor (org.apache.struts.action.RequestProcessor) as well. The ActionServlet delegates request handling to the request processor. With Struts 1.1, you no longer have to extend the ActionServlet for customization; instead, you subclass the RequestProcessor. If a Struts 1.0-based application did not extend the ActionServlet, then no changes are required to use the RequestProcessor. If ActionServlet was subclassed, you should extend the RequestProcessor instead.

The other primary enhancement, as mentioned, is in the Struts Action. Struts 1.1 introduced a new method, execute( ), that subclasses should implement instead of the perform() method. Example 1-1 shows a simple Action that implements the perform() method.

Example 1-1. Struts 1.0 Action

package org.apache.struts.webapp.example;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;

public final class ExampleAction extends Action {
    public ActionForward perform(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
            throws IOException, ServletException {

        try {
            ExampleService service = new ExampleService( );
            Service.doService( );
        }
        catch (ServiceException ex) {
            throw new ServletException( ex );
        }
        return (mapping.findForward("success"));
    }
}

Example 1-2 is the same Action using Struts 1.1.

Example 1-2. Struts 1.1 Action

package org.apache.struts.webapp.example;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;

public final class ExampleAction extends Action {
    public ActionForward execute (ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
            throws Exception {

            ExampleService service = new ExampleService( );
            Service.doService( );

            return (mapping.findForward("success"));
    }
}

As you can see, with the Struts 1.1-based Action, the exception handling no longer needs to be performed in the method. Struts 1.1 now supports exception handling as part of the framework as will be shown in Recipe 9.1.

You aren't required to change your Actions to use the execute( ) method, as Struts 1.1 still supports the perform( ) method; however, the method is deprecated.

Warning

If you are migrating directly from Struts 1.0 to Struts 1.2, Struts 1.1 deprecations, such as the perform( ) method, have been formally removed from the Struts 1.2 API.

Though it will continue to function as is, I recommend convert your code to use the execute( ) method as soon as you can. Doing so will reduce the work to convert to Struts 1.2. More significantly, it will allow to you take advantage of the Struts 1.1 exception-handling capability.

See Also

Recipe 9.1 details exception processing with Struts 1.1.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required