Tutorials > Program model > Extend a Struts action

< Previous | Next >


Test the implementation

This tutorial lesson is about testing the implementation.

In order to test MyNewAction, we will create a JSP page, MyReferrerPage.jsp, to be used as a test referring page:


Procedure

  1. In the Enterprise Explorer view, expand the Stores > WebContent > ConsumerDirect_name

  2. Right-click ConsumerDirect _name and select New > File

  3. In the New File dialog that opens, type MyReferrerPage.jsp in the File name field and click Finish.

  4. If it does not automatically open for editing, double-click MyReferrerPage.jsp in the Enterprise Explorer view under Stores > WebContent > ConsumerDirect_name .

  5. Change to the Source view of the editor.

  6. Paste the following source into the file:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o../images/locale/screensnap/xhtml1/DTD/xhtml1-transitional.dtd">
    <%
    //********************************************************************
    //*-------------------------------------------------------------------
    //* Licensed Materials - Property of IBM
    //*
    //* WebSphere Commerce //*
    //* (c) Copyright IBM Corp. 2002, 2004, 2009
    //*
    //* 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/ConsumerDirect/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));
       cookie.setPath("/");
       response.addCookie(cookie);
       response.sendRedirect(redirectURL);
    %>
    

  7. Modify the cookie values as needed and save the file.

  8. Test the cookie functionality:

    1. Start the WebSphere Commerce Test Server.

    2. Navigate to the Stores > WebContent > ConsumerDirect_name directory.

    3. Select the MyReferrerPage.jsp file and from its pop-up menu select Run > Run on Server.

    4. A message might display asking you to select a server. Select Choose an existing server and click Finish.

    5. The MyReferrerPage.jsp page is displayed in the browser.

    6. Copy the following line into the browser Address bar:

      javascript:alert(document.cookie)
      

    7. In the JavaScript popup window that is displayed, examine the cookies and ensure that the REFERRER values exist and are correct.

< Previous | Next >


+

Search Tips   |   Advanced Search