Why is opencms used in JSP?
Opencms provides many features to help you speed up development, such as templates, user management, permission settings, and Cache Management. You can also create dynamic navigation based on the file structure of opencms, all files in the opencms Virtual File System (VFS) are stored in the database. to access any opencms VFS information, you must use the jsp api provided by opencms.
Two basic methods
There are two methods to access opencms in JSP files:
1. Use opencms label library, usually starting with "<CMS:>"
2. Use "opencms" in your scriptorg.opencms.jsp.CmsJspActionElement
"
The general functions can be completed using both methods, which is usually a matter of personal experience and happiness. jsp labels are easier for beginners in Java, I don't even know Java, But I have rich experience in HTML. I can use these tags just like HTML tags. On the other hand, rich Java veterans may be more keen on using script code (Using JavaBeans to process business logic) for more flexible control and higher performance.
If you are using opencms labels, you should consider combining them with common JSP labels to complete some functions, such as loop, if-then, and enumerations. We recommend that you use jstl (java standard label Library) in the jsp2.0 standard. There are some examples of jstl in the alkacon document (system help document after opencms is successfully installed.
If you want to implement more advanced functions, such as navigation or forms, you must use APIs to write scripts.
Opencms <CMS:> label
To use the opencms tag library, you must declare it in your JSP as follows:
<%... @ Taglib prefix = "CMS" uri = "http://www.opencms.org/taglib/cms" %>
<H1> simple taglib example
The installed opencms version is <CMS: info property = "opencms. Version"/>. <p>
The "title" property of this file is "<CMS: property name =" title "/>". <p>
Link to a file in the opencms VFS <a href = "<CMS: link>/alkacon-documentation/index.html </CMS: link>"> like this </a>. <p>
The execution result is as follows:
Opencms script API
To access opencms APIs in your scripts, you must first create a JavaBeanThe instance of org. opencms. jsp. cmsjspactionelement is as follows:
<% @ Page import = "Java. util. *, org. opencms. jsp. *" %> <%
// Create a JSP Action Element
Cmsjspactionelement CMS = new cmsjspactionelement (pagecontext, request, response );
// Get a simple navigation of all pages/subfolders in the current folder
List list = cms. getnavigation (). getnavigationforfolder ();
Iterator I = List. iterator ();
Out. println ("While (I. hasnext ())...{
Cmsjspnavelement Ne = (cmsjspnavelement) I. Next ();
Out. println ("<li> <a href =" "+ cms. Link (ne. getresourcename () +" "> ");
Out. println (ne. gettitle () + "</a> ");
}
Out. println ("</ul> ");
%>
The running result is as follows: