WebSphere Commerce JSP programming best practices
These Commerce-specific best practices are intended to be used in conjunction with the common Web application development standards and practices, such as those associated with the Java EE at a Glance technology and the JavaServer Pages technology, as well as with general principles and conventions of WebSphere Commerce.
- JSP programming best practice: Use JSTL in place of Java code
JavaServer Pages Standard Tag Library (JSTL) is a collection of JSP tags that provide standard functionality most commonly sought by JSP page authors. JSTL has support for conditions, iteration, locale-sensitive formatting, and so forth. It also has an expression language (EL) that allows page authors to control how data is retrieved and displayed.- JSP programming best practice: Use the Commerce-specific tag for bean activation
WebSphere Commerce data beans require activation prior to their use. WebSphere Commerce provides a Commerce-specific version of the useBean tag, <wcbase:useBean>, that performs data bean activation in Java-free manner and is the recommended method of data bean activation in store JSP pages.- JSP programming best practice: Use Commerce-specific maps to access request parameters
WebSphere Commerce provides the following Commerce-specific versions of the implicit JSP objects param and paramValues to facilitate access to decrypted HTTP request parameters:- JSP programming best practice: Use the StoreErrorDataBean data bean for error handling
To display store-specific error messages in JSP pages, use the StoreErrorDataBean data bean.- JSP programming best practice: Use an appropriate inclusion mechanism
JSP supports two inclusion mechanisms: Static include and Dynamic include.- JSP programming best practice: Use the .jspf extension for JSP segments
A JSP page can consist of one or more files: for example, the file containing a top-level JSP page, several files containing dynamically included JSP pages, and several files containing statically included JSP segments. Unlike the top-level or dynamically included pages, JSP segments need not be legal JSP pages and thus may not compile properly.- JSP programming best practice: Use the escapeXml attribute to preserve HTML formatting
By default, the value of the escapeXml attribute of the JSTL <c:out> tag is true. This default behavior ensures that HTML special characters, such as <, >, &, ', or ", contained in output strings are converted into their corresponding character entity codes and displayed properly in the HTML page produced by the JSP page. In some common WebSphere Commerce store scenarios, however, this behavior is counterproductive. One such scenario is the display of prices in globalized stores:- JSP programming best practice: Ensure XHTML-compliance
JSTL and HTML elements of your JSP pages should conform to the W3C XHTML standard and recommendations.- JSP programming best practice: Use the post method for form submission
Data can be sent from client to server by way of an HTML form using either the get or the post method. Servlets can handle either method properly by appropriately parsing and decoding the incoming request. In general, use of the post method is recommended due to the following reasons:- Changing the appearance of a starter store
The storefront appearance is an important factor in improving customer experience. In this tutorial, the cascading style sheets (CSS) are modified to change the color and layout of the storefront. The new style is then made available as a display option for a starter store. The new style is selected in the Change Style wizard in WebSphere Commerce Accelerator or in the Management Center Store Management tool.Enable the Struts 2 file upload feature
We can take full advantage of the WebSphere Commerce Struts 2 file upload feature. In order to use Struts 2 uploads, ensure that you have enabled the capability.
Related concepts
WebSphere Commerce framework overview
Model-View-Controller design pattern
Display design pattern
Supporting globalization
Related reference
JSP programming best practice: Use the StoreErrorDataBean data bean for error handling
JSP programming best practice: Use the escapeXml attribute to preserve HTML formatting
JSP programming best practice: Use an appropriate inclusion mechanism
JSP programming best practice: Use the .jspf extension for JSP segments
JSP programming best practice: Use JSTL in place of Java code
JSP programming best practice: Use Commerce-specific maps to access request parameters
JSP programming best practice: Use the post method for form submission
JSP programming best practice: Use the Commerce-specific tag for bean activation
JSP programming best practice: Ensure XHTML-compliance