14.3 Migrating Struts Web applications

 < Day Day Up > 

The following list presents the steps you have to follow to migrate an existing Struts Web application into a Struts portlet application. Most of the changes only affect the configurations files.

  1. Make sure the existing Struts application has been built as a Struts 1.1 application.

  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.

  3. The Web deployment descriptor must be updated to use the WpsStrutsPortlet as the servlet class instead of the ActionServlet.

  4. The servlet mapping for Struts actions must be specified as the struts-servlet-mapping init parameter.Create a portlet.xml. The PortalStrutsExample.war can be used as an example.

  5. Modify the struts-config.xml to specify the WpsRequestProcessor as the controller.

  6. Modify tags that use pageContext.forward() to use the PortletApiUtils forward.

  7. Modify JSPs that use a forward to use the logic forward tag.

  8. Modify JSPs as necessary to use the Struts tags for creating URLs, like the Struts Link and Form tags.

  9. 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.

  10. 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.

  11. 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 .

To migrate the WebBookStruts Web application into a portlet application, proceed as follows .

  1. In the Portlet perspective choose File -> New -> Portlet Application Project from the main menu.

  2. In the Create a Portlet Project window, enter a project name of StrutsBookPortlet and check Create empty portlet . Click Next > .

  3. In the J2EE Settings page, select a J2EE Level of 1.2 , check Existing enterprise application project and select DefaultEAR . Click Finish .

  4. From the main menu, select File -> Import... Choose WAR file and click Next < . Browse to WSAD_INSTALL_DIR\ runtimes \portal_v50\dev\struts\StrutsPortlet. Check PortalStrutsBlank.war . As the Web Project, select the existing Web project StrutsBookPortlet . Check Overwrite existing resources without warning and click Finish .

    Figure 14-7. Import the PortletStrutsBlank.war file

    graphics/14fig07.jpg

  5. Next, we copy all resources from the Web application to the portlet application.

    1. In the J2EE Navigator, select all packages from the WebBookStruts project and choose Copy from the context menu.

      Figure 14-8. Copy the java files from the Web to the portlet project

      graphics/14fig08.gif

    2. Select the Java Source folder from the StrutsBookPortlet project and choose Paste from the context menu.

    3. Copy all JSP from the WebBookStruts/Web Content folder to the StrutsBookPortlet/Web Content folder.

    4. Delete index.jsp from the StrutsBookPortlet/Web Content folder.

    5. In the StrutsBookPortlet/Web Content folder, rename addABook.jsp to index.jsp .

    6. Open index.jsp. Change the lines:

       <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 

      to:

       <%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %> 
    7. Remove all tags between <head> and </head> , then remove all head and body tags.

    8. Repeat steps f and g for the remaining two JSPs in StrutsBookPortlet.

    9. Delete struts-config.xml from the StrutsBookPortlet/Web Content/WEB-INF folder.

    10. Copy struts-config.xml from WebBookStruts/Web Content/WEB-INF folder to the StrutsBookPortlet/Web Content/WEB-INF folder.

    11. Open StrutsBookPortlet/Web Content/WEB-INF/struts-config.xml. The Struts config editor opens. Switch to the XML Source tab.

    12. Include the following code before the message-resources tag:

       <!-- ============================= Controller Configuration --> <controller processorClass="com.ibm.wps.portlets.struts.WpsRequestProcessor"> </controller> 

      Note : Because WebSphere Portal does not support the back button of the Web browser, it can be difficult to navigate back through a number of screens to a location earlier in the browser history. To browse back from the addABook.Result.jsp or error.jsp, we have to add a homeFromStatic forward to ort action mapping which references the static content.

    13. Switch to the Global Forwards tab of the Struts configuration editor. Click the New button. Enter a forward name of homeFromStatic and a path of /index.jsp .

      Figure 14-9. The Struts configuration editor

      graphics/14fig09.jpg

    14. Open the addABookResponse.jsp file. Insert the following code snippet before the </html> tag.

       <html:link forward="homeFromStatic">Back to index</html:link> 
    15. Repeat the last step for the error.jsp.

    16. Save and close the struts-config.xml file.

Running the Struts portlet

Execute the following steps to run the Struts portlet:

  1. To run a project in the WebSphere Studio Site Developer Test Environment, it is necessary to add the portlet project to the test environment. You can use a test server you created before or create a new server.

    1. Click the Server Configuration tab (on the navigator panel).

    2. Expand the Servers tree.

    3. Right-click WebSphere Portal V5.0 Test Environment or your custom name... .

    4. Click Add -> DefaultEAR to add your project to the test environment.

      Figure 14-10. Adding the Struts portlet project to the test environment

      graphics/14fig10.jpg

    5. Now click the J2EE Navigator tab to see your project again. Right-click StrutsBookPortlet . Then click Run on Server . If the Server Selection window opens, select your portal test environment and click Finish .

      Figure 14-11. WebBook Struts application running within WebSphere Portal

      graphics/14fig11.jpg

      When you press the Submit button, the Struts framework within WebSphere Portal executes the AddABook action and opens the addABookResponse.jsp or error.jsp.

 < Day Day Up > 


IBM WebSphere Portal V5 A Guide for Portlet Application Development
IBM Websphere Portal V5: A Guide for Portlet Application Development
ISBN: 0738498513
EAN: 2147483647
Year: 2004
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net