WebSphere Commerce JSP programming best practices
This section offers the following selection of JSP programming best practices, which promote development of reusable and maintainable JSP pages within the WebSphere Commerce store development framework:
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 J2EE 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:Related concepts
WebSphere Commerce framework overview
Model-View-Controller design pattern
Display design pattern
Starter store conventions
Supporting globalization