Search the documentation
 Show GitHub edit links  Hide GitHub edit links
Documented since: 9.0 Latest revision for: 9.5.2 Valid for OpenCms: 10.5.3

JSPs (Java Server Pages) provide a powerful way to build web pages dynamically. They are the way, web pages are generated in OpenCms. In essence a JSP is a Java program that looks like HTML code and, if executed, creates a HTML page. The particular advantage of a JSP is that arbitrary Java code can be executed to produce HTML output. There are three ways to accomplish dynamic HTML creation by executing Java code:

  • Special tags provided via taglibs
  • The expression language (EL)
  • Writing scriptlet code

In order to keep your JSPs simple and maintainable, it is good style to avoid scriptlet code and use tags and the EL. For more details about JSPs in general, in particular the JSTL (the standard tag libraries) and the EL, please consult the very good books or tutorials around.

When writing JSPs in OpenCms, you should be aware of the following:

  • JSPs are managed/added via the OpenCms workplace and have the resource type “jsp”
  • Each JSP exists in an “offline” and an “online” version
  • JSPs can't be exported statically, but there rendered output can be cached
  • To increase performance you might have to alter FlexCache settings

In OpenCms JSPs are used for several purposes:

  • Templates that provide for WYSIWYG editable pages
  • Formatters for XML contents
  • Pages with special functionality, e.g. login forms, search result pages, etc.

To easily create JSPs for the purposes just described, OpenCms comes with a special API for JSPs that consists mainly of two parts:

  • The OpenCms taglib
  • A set of Java beans to make OpenCms functionality accessible via the EL

This page forwards you to the relevant topics on writing JSPs in OpenCms.

Using the EL

The expression language (EL) provides easy access to special Java objects, so called beans. OpenCms makes using the EL easy by providing a rich set of beans to access OpenCms functionality in JSPs.

  • Get an overview on Java beans used in EL and their purpose. Follow direct links to the according JavaDoc of the beans.

  • Get an overview on commonly used EL expressions.

  • Have a look at the demos where formatters or function providers are included. You will find a lot of examples on using the EL.

  • An object of the CmsJspStandardContextBean is available in each JSP via the variable cms. In most cases (except access to contents, where special beans are exposed via tags) it is the starting point to access OpenCms functionality in a JSP.

Using the <cms:>-taglib
  • Use the OpenCms taglib <cms:> to easily access OpenCms functionality in JSPs.

  • A JavaDoc-like autogenerated documentation on all tags and EL-functions provided via the <cms:>-taglib.

  • Have a look at the demos where formatters or function providers are included. You will find a lot of examples on using the the <cms:>-taglib.

You can improve this page

Please contribute your suggestions or comments regarding this topic on our wiki. For support questions, please use the OpenCms mailing list or go for professional support.