Migrate existing Struts applications


The Jakarta Struts distribution ships an example Struts application that demonstrates the features of Struts, including implementing Struts Actions, creating custom tags, using the Struts tag libraries, authoring JSPs, and form validation. The Struts Portlet Framework demo builds on this example by incorporating WebSphere Portal features, including support for help mode and WML markup. The Struts example required very few changes to enable it for the Struts Portlet Framework.

The file structure of the WAR file for a Struts Portlet Framework is the same as that used for a Struts servlet. The Struts application in the portal server is a WAR file just like it is in the servlet environment. The portlet WAR file has some additional JARS and other requirements, but the basis of the implementation is similar to the servlet application. See WAR file directory structure for more information.

 

Migrate the existing servlet based Struts application

Existing Struts applications can be migrated using the Struts Portlet Framework so the application can be deployed in WebSphere Portal. Since Struts is a framework there are many variations to how the application can be built with Struts. There are also numerous other frameworks that may also be encorporated into the Struts application. The steps in this section can be used as a starting point for the migration effort, but may not cover all of the issues that can be encountered.

  1. Make sure the existing Struts application has been built as a Struts 1.1 application. (See The Struts Application Framework.)

  2. Update the Struts action so that it does not write to the response object. This is not supported in the Struts Portlet Framework because of WebSphere Portal's two phase processing. (See Changes to Struts application code.)

  3. The web deployment descriptor must be updated to use the WpsStrutsPortlet as the servlet class instead of the ActionServlet. (See Changes to the Web deployment descriptor.)

  4. The servlet mapping for Struts actions must be specified as the struts-servlet-mapping init parameter. (See Changes to the Web deployment descriptor.)

  5. Create a portlet.xml. The PortalStrutsExample.war can be used as an example. (See Portlet deployment descriptor.)

  6. Modify the struts-config.xml to specify the WpsRequestProcessor as the controller. (See Struts configuration file.)

  7. Modify tags that use pageContext.forward() to use the PortletApiUtils forward. (See Forwards and redirects.)

  8. Modify JSPs that use a forward to use the logic forward tag. (See Changes that affect Struts JSPs.)

  9. Modify JSPs as necessary to use the Struts tags for creating URLs, like the Struts Link and Form tags. (See Create portlet URIs).

  10. The JAR files from the WEB_INF/lib directory of the PortalStrutsBlank.war must be used. These files are the Struts JARs and the required Struts Portlet Framework JARs.

  11. The TLD files must be updated from the WEB_INF/lib directory of PortalStrutsBlank.war. Verify the taglib attributes and that the JSP correctly reference the TLD files. This has been a common source of problems when migrating existing applications.

  12. The JSPs should be modified so they do not use html, head and body elements. All HTML output to the portal is written in the context of an HTML table cell. (See Portlet Development Best Practices and Coding Guidelines.)

See also