How to manage JSPs in OpenCms

Source: Internet
Author: User
Tags file system include resource versions root directory

All the files in OpenCms are usually stored in the database, which is often called the OpenCms VFS (virtual file system). That is, the file structure seen in the OpenCms workspace does not exist on the RFS (the real file system, the hard drive) (except for static export operations), however, for JSP to work properly, all OpenCms JSP files are mapped to the real file system. That is, it can be found on the hard disk.

To understand this process, let's take a look at how the standard JSP files are handled:

The JSP file must be stored in the root directory of the Web application;

The JSP file must end with "*.jsp" (can be configured in Web.xml file);

The servlet container accepts requests for JSP files, and the requested file is first converted to Java class source, with the extension ". Java".

In this process, the JSP directives (such as <%@ include file= "..."%>) is also transformed into Java source code.

The generated ". Java" source code is then compiled into a class that implements the Servlet interface.

Finally, the servlet invokes the service () method.

To enable OpenCms to be independent of the servlet container, it uses a simple trick: mapping a JSP from a virtual file system to a real file system, as follows:

All OpenCms resource requests are controlled by the OpenCms servlet and are usually mapped to/opencms/opencms;

Once OpenCms receives a request for a JSP resource, it "stores" the requested JSP file under "/web-inf/jsp/" under its own WEB application root directory;

Since OpenCms uses both online and offline to differentiate between "publish" and "edit" versions of a resource, the online and offline two subdirectories are also generated under this directory (/web-inf/jsp/);

In both directories, it stores the JSP file as a file with a full VFS path and a ". jsp" suffix;

For example, the JSP file is "/index.jsp" in the VFS, and it is mapped to the "/web-inf/jsp/online/index.jsp.jsp" in the real file system, which is called the JSP for "file name conversion".

When OpenCms stores resources, the JSP file that the JSP directives (<%@ include file= "..."%> and <%@ page errorpage= "..."%) points to is also handled as "file name conversion". That is to map them to the real file system;

Suppose we have a file in the Web application directory called "file.jsp";

The OpenCms servlet calls RequestDispatcher ("{file.jsp}"). Include () and passes control over to the standard servlet container. The rest of the steps are the same as the standard JSP processing described above.

How do I differentiate between online and offline JSP versions?

It's simple: Because OpenCms is stored in two directories for different versions of JSP under online and offline, the servlet container treats them as a different file. Also do it to the offline under the JSP changes will not affect the JSP under the online.

Note: The JSP under online and offline has the same Web application context, because they share an application context object, online and offline JSP pages access the same set of data, and imprudent use can cause unintended side effects. You can avoid these side effects by strictly controlling access to application context objects.

How do I use JSP in OpenCms static export?

Using OpenCms static file export can improve the performance of your Web site. OpenCms The JSP file management also fully supports the static export. Of course, JSP is usually used in dynamic pages, so the default generated JSP file's Export property defaults to False, in case you want to export the JSP, you must manually set the JSP's Export property to True.

In order to support links to statically exported resources, the <cms:link> tag or Cms.link method (<cms:link> usage) is used in OpenCms.

In addition, when you include a filename in the JSP directives, do not use the syntax like "<jsp:directive.include file=" ... "/>", but instead use <%@ include file= "..."%> Syntax because the syntax for "/>" like "<jsp:directive.include file=" is not supported in OpenCms, which means that the JSP file in this syntax cannot be processed and cannot be mapped to a real file system. However, this syntax is supported for other names that do not contain filenames, such as: <jsp:usebean id= "..."/> or <jsp:setproperty name= "..."/>, which can be used normally in OpenCms JSP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.