JSP programming best practice: Ensure XHTML-compliance

JSTL and HTML elements of your JSP pages should conform to the W3C XHTML standard and recommendations.

  • Use lowercase for all element and attribute names. For example, <table>, and not <TABLE>.
  • Enclose all attribute values in double quotation marks. For example, <img value="car.jpg" width="20" />, and not <img value='car.jpg' width=20/>.
  • Ensure that every element has an end tag or is self-terminating if it is empty. For example, <p>Welcome to HCL Commerce!</p> or <c:set var="xyz" value="uvw" />.
  • For HTML-compatibility, include a space in all empty element tags before closing the tag. For example, <br /> instead of <br/>.
  • Ensure that the HTML page that your JSP page produces begins with a valid document type declaration. For example:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

To ensure XHTML-compliance, use XHTML validators, such as the HCL Commerce Developer HTML validator (right-click on the file and select Run Validation) or the W3C Markup Validation Service.