Testing the extended Struts action

In this lesson, you test your implementation to ensure that you successfully created and extended the struts action class, com.ibm.commerce.sample.struts.MyNewAction.

About this task

To test MyNewAction, you create a JSP page, MyReferrerPage.jsp, to be used as a test referral page:


  1. In the Enterprise Explorer view, expand navigate to Stores/WebContent/store_directory.
    Where store_directory is the name of the directory for your store, for instance, Madisons or Aurora.
  2. Right-click your store_directory; select New > File.
  3. In the New File dialog that opens, enter MyReferrerPage.jsp in the File name field and click Finish.
  4. If the MyReferrerPage.jsp does not open automatically for editing, navigate to Stores/WebContent/store_directory and open MyReferrerPage.jsp for editing.
  5. In the editor, click Source to view the source code for the file.
  6. Copy and paste the following source code into the file:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    //* Licensed Materials - Property of IBM
    //* WebSphere Commerce
    //* (c) Copyright IBM Corp. 2002, 2004, 2009, 2012
    //* US Government Users Restricted Rights - Use, duplication or
    //* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
    //* This JSP can be called directly from a URL such as http://<hostname>/<webpath>/<storedir>/cookie.jsp.
    //* For example: http://localhost/webapp/wcs/stores/servlet/Aurora/cookie.jsp
    //* It sets the REFERRER cookie and redirects the browser to index.jsp to display the store's home page.
    <%@ page import="java.net.URLEncoder" %>
       String referrerURL = "http://www.example.com/index.html";
       String redirectURL = "index.jsp";
       Cookie cookie = new Cookie("REFERRER", URLEncoder.encode(referrerURL));
  7. Modify the cookie values as needed and save the file.
  8. Test the cookie function:
    1. Start or restart the WebSphere Commerce Test Server.
    2. In the Enterprise Explorer view, navigate to the Stores/WebContent/store_directory directory.
    3. Right-click the MyReferrerPage.jsp file; select Run As > Run on Server.
    4. In the Run on Server window, select your WebSphere Commerce Test Server and click Finish.
    5. The MyReferrerPage.jsp page displays in the browser.
    6. Copy the following into the browser Address bar:
    7. In the JavaScript window, examine the cookies and ensure that the REFERRER values exist and are correct.
      If the values exist and are correct, you successfully created and extended the struts action class, com.ibm.commerce.sample.struts.MyNewAction.