Struts is one of the best-known open-source embodiments of the Model-View-Controller (MVC) framework, which provides a convenient way for modular applications to cleanly separate logic, presentation, and data. JavaServer Pages (JSP) typically plays the View role in the MVC framework, which generates a dynamic user interface (UI) based on business logic and data. Struts is very popular because it helps developers effectively design Web applications.
IBM ® WebSphere® Portal has a built-in Struts Portlet Framework that enables Struts to extend its popularity to portal applications. Existing Struts applications can be migrated using the Struts Portlet Framework and then deployed in WebSphere Portal.
IBM WebSphere Studio Application Developer (hereafter called Application Developer) has built-in tooling and run time support for developing and unit testing Struts applications. With the WebSphere Portal Toolkit installed in Application Developer, portal applications can also be developed and unit tested with WebSphere Studio.
This article describes how to migrate an existing Struts application to a portal application with WebSphere Studio. This article assumes that you have basic knowledge of Struts and the Struts tools in WebSphere Studio. (For basic information on this topic, see Writing a Simple Struts Application using WebSphere Studio V5.)
The portal application created in this article is targeted on WebSphere Portal V5. Therefore, the following software is required to follow this example:
- WebSphere Studio Application Developer Version 5.01
- WebSphere Portal Toolkit Version 5 with WebSphere Portal V5 Unit Test Environment installed.
If you need to install this software, below is a brief outline of the sequence of steps for installing what you need:
- Install WebSphere Studio Application Developer V5.
- Install WebSphere Studio Application Developer 5.01 PTF.
- Install WebSphere Application Server 5.01 PTF to the WebSphere Test Environment (refer to
WPS_CDSets\cd0\PortalToolkit\InstallGuide\was_ptf1.htmfor more details) - Install WebSphere Application Server 5 Interim fixes (refer to
WPS_CDSets\cd0\PortalToolkit\InstallGuide\was_ptf1.htmfor more details). - Install WebSphere Portal Toolkit V5. During installation, be sure to select the WebSphere Portal V5 unit test environment. You will be prompted for the WebSphere Portal V5 CD or installation folder, so be sure to either have the CD on hand or download the image before the installation.
Create and test a simple Struts application
We will begin by downloading a sample Struts project that has already been created. If you would like details on creating a simple struts application with WebSphere Studio V5, refer to the article Writing a Simple Struts Application using WebSphere Studio V5, which also applies to WebSphere Studio V5.01. The difference is that WebSphere Studio V5 supports Struts 1.1 beta 2, while WebSphere Studio V5.01 supports Struts 1.1 beta 3; you will need to use the Struts 1.1 beta 3 framework for the Struts Web projects you plan to migrate to portal applications.
Download the SimpleStruts.ear included with this article, then follow these steps to test the SimpleStruts project:
- Import
SimpleStruts.earinto the Application Developer workspace. You will have two projects created:SimpleStrutsandSimpleStrutsWeb. - Create a WebSphere Test Environment V5 server instance and configuration.
- Add the
SimpleStrutsapplication into the server configuration. - Start the server.
- Right-click on the submitpage.jsp under SimpleStrutsWeb\Web Content and select Run on Server from the context menu.
Figure 1. A simple Struts application
- Submit the form with some information to see the result.
- After the test, stop the server.
Migrate the simple Struts application to a Portal application
- Replace the Apache Struts Framework with the Portlet Struts Framework; WebSphere Portal rewrote the implementation of the Apache Struts Framework for the Portal environment, so you need to use the corresponding JAR files and TLD files as follows:
- Import
WSAD_InstallDir\runtimes\portal_v50\dev\struts\StrutsPortlet\PortalStrutsBlank.warinto the workspace. UsePortletStrutsBlankas the Web project name and create a new Enterprise Application project to contain the Web project. - Copy all the JAR files from
PortletStrutsBlank\Web Content\WEB-INF\libtoSimpleStrutsWeb\Web Content\WEB-INF\lib. - Copy all the TLD files from
PortletStrutsBlank\Web Content\WEB-INF\tldtoSimpleStrutsWeb\Web Content\WEB-INF. - Import
portlet.tldintoSimpleStrutsWeb\Web Content\WEB-INF\. This tag library file can be found inWSAD_InstallDir\runtimes\portal_v50\shared\app\WEB-INF\tld.
- Import
- Modify the Web Deployment Descriptor:
- Open
web.xmlunderSimpleStrutsWeb\Web Content\WEB-INF. - Click on the Servlets tab, and change the name of the servlet from action to Struts.
- Change the Servlet class of Struts to com.ibm.wps.portlets.struts.WpsStrutsPortlet. You may have difficulties changing the class name from the Servlets tab of the editor because the editor does not recognize that WpsStrutsPortlet is a Servlet. Therefore, you need to switch to the Source tab of the editor to change the classname as follows:
<servlet-name>Struts</servlet-name> <servlet-class>com.ibm.wps.portlets.struts.WpsStrutsPortlet</servlet-class> - Change the URL mapping of the Struts Servlet from
/*.doto/Struts/*. - Make sure the initialization parameter config points to the Struts configuration file, and then add a new initialization
parameter named struts-servlet-mapping:
Parameter name Parameter value config /WEB-INF/struts-config.xmlstruts-servlet-mapping *.do
- Click on the Pages tab, remove all the items in the Welcome Pages list, and add
submitpage.jspto the Welcome Pages list. - Save the Web Deployment Descriptor.
- Open
- Modify the Struts Configuration File: Add the following element into the
<struts-config>element ofstruts-config.xmlunderSimpleStrutsWeb\Web Content\WEB-INF:<controller processorClass="com.ibm.wps.portlets.struts.WpsRequestProcessor">
</controller> - Create a Portlet Deployment Descriptor:
- Copy
portlet.xmlfromPortalStrutsBlank\Web Content\WEB-INFtoSimpleStrutsWeb\Web Content\WEB-INF. - Open
portlet.xmlin an editor. - From the Portlet Application item, change the Display name to
Pizza Order Application, and change the UID field toPizzaOrderApplicaton:1as shown in Figure 2. You need to make sure the UID is unique across all portal applications deployed to WebSphere Portal.
Figure 2. Modify portlet.xml
- From the Portlet_1 item, under Portlet Application, change the Display name of the portlet to
Pizza Order Portlet. Click the Browse button, and then select Struts as the implementation of the portlet from the pop-up window, as shown in Figure 3.
Figure 3. Modify portlet.xml
- Select the Concrete Portlet Application item from the editor. Change the Display name to
Pizza Order Applicationand change the UID toPizzaOrderApplication:1.1as shown in Figure 4.
Figure 4. Modify the portlet.xml
- Select the Portlet_1 item, under Concrete Portlet Application, and change the Display name to
Pizza Order Portlet. Change the values of Title, Short title, and Description toOrder a Pizza. - Save the Portlet Deployment Descriptor.
- Copy
- Modify the HTML tags in the JSPs: A portlet cannot contain regular HTML tags, so You need to make the following changes for all JSPs in the application:
- Remove the
<!DOCTYPE>tag. - Add a new tag library:
<%@ taglib uri="/WEB-INF/struts-portal-html.tld" prefix="portalhtml" %> - change
<HEAD>tags to<portalhtml:head> - change
<BODY>tags to<portalhtml:body>.
- Remove the
- Test the Portal application:
- Create a WebSphere Portal V5 Test Environment server instance and configuration.
- Add enterprise project SimpleStruts into the server configuration.
- Start the server.
- Right-click on the project SimpleStrutsWeb and choose Run on the server... from the context menu.
- The first page of the portal application will display as shown in Figure 5.
Figure 5. Test the portal application after migration
- Submit the form with some information to see the result. (You can obtain a migrated copy of the application,
SimpleStrutsPortal.ear, from the Download section in this article.)
With the streamlined process now included within WebSphere Studio, it is easier than ever to migrate and deploy a Struts application to WebSphere Portal by following the general instructions provided here.
| Name | Size | Download method |
|---|---|---|
| strutsdownload.zip | 2.4 MB | FTP |
Information about download methods
- Writing a Simple Struts Application using WebSphere Studio V5
- Apache Struts Tiles User Guide
- Install WebSphere Studio Application Developer 5.01 PTF
Colin Yu is currently working as a Technical Designer on Business Scenario Development team at the IBM Software Solutions Toronto Lab. Colin received a Bachelor of Engineering degree in 1995 and a Master of Applied Science degree from the University of Waterloo, Ontario in 2000. Colin is an IBM Certified Enterprise Developer and Systems Expert on WebSphere Application Server, and an IBM Certified Solution Developer on WebSphere Studio Application Developer and VisualAge for Java.




