Tutorials > Program model > Extend a Struts action
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
- In the Enterprise Explorer view, expand the Stores > WebContent > ConsumerDirect_name
- Right-click ConsumerDirect _name and select New > File
- In the New File dialog that opens, type MyReferrerPage.jsp in the File name field and click Finish.
- If it does not automatically open for editing, double-click MyReferrerPage.jsp in the Enterprise Explorer view under Stores > WebContent > ConsumerDirect_name .
- Change to the Source view of the editor.
- 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); %>
- Modify the cookie values as needed and save the file.
- Test the cookie functionality:
- Start the WebSphere Commerce Test Server.
- Navigate to the Stores > WebContent > ConsumerDirect_name directory.
- Select the MyReferrerPage.jsp file and from its pop-up menu select Run > Run on Server.
- A message might display asking you to select a server. Select Choose an existing server and click Finish.
- The MyReferrerPage.jsp page is displayed in the browser.
- Copy the following line into the browser Address bar:
javascript:alert(document.cookie)
- In the JavaScript popup window that is displayed, examine the cookies and ensure that the REFERRER values exist and are correct.