Skip to content
OpenCms documentation
OpenCms documentation

JSP development

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 in the virtual file system 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 their 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 realize 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:

Accessing content values via value wrappers, generating responsive images, and also generating JSON output are three recurring requirements when developing a modern website template, thus described in extra chapters here.