Zimlet Developers Guide:Java and JSP: Difference between revisions
No edit summary |
No edit summary |
||
Line 21: | Line 21: | ||
|- | |- | ||
|[[ZCS 6.0:Zimlet Developers Guide:Portal|Portal]] | |[[ZCS 6.0:Zimlet Developers Guide:Portal|Portal]] | ||
|- | |||
|[[ZCS 6.0:Zimlet Developers Guide:Zimlet Tab|Zimlet Tab]] | |||
|- | |- | ||
|[[ZCS 6.0:Zimlet Developers Guide:Internationalization|Internationalization]] | |[[ZCS 6.0:Zimlet Developers Guide:Internationalization|Internationalization]] |
Revision as of 16:39, 10 January 2010
This section describes how to incorporate Java and JSP in your zimlets.
JSP
JavaServer Pages (JSP) allow you to create dynamic page content with Java. The JSP files included with your zimlet are executed on the Zimbra server and can call Java APIs to perform server-side data retrieval and manipulation.
To reference a JSP file from your zimlet, you need the page URL (sometimes referred to as the "resource location"). The following sections describe how to determine the JSP file resource location.
Calling JSP from Zimlet Definition File
If you plan to call your JSP page from the Zimlet Definition File (for example, from an <actionUrl>
element), the path to the JSP is:
/service/zimlet/{zimlet-name}/{jsp-file-name}.jsp
For example, calling a JSP file named "jspfile.jsp" (located at the root of your zimlet package) from an <actionUrl>
element:
<actionUrl method="get" target="/service/zimlet/com_zimbra_simplejspaction/jspfile.jsp" />
If using the Development Directory, the path should include _dev
. For example:
<actionUrl method="get" target="/service/zimlet/_dev/com_zimbra_simplejspaction/jspfile.jsp" />
Calling JSP from Zimlet Handler Object
If you plan to call your JSP page from your Zimlet Handler Object in JavaScript, you can use ZimletBaseObject.getResource()
to determine the JSP page resource location. For example:
var jspUrl = this.getResource("jspfile.jsp");
See the JavaScript API Reference for more information on the ZimetBaseObject
class and associated methods.
Once you have the JSP resource location, you can invoke the page using AjxRpc.invoke
.
var response = AjxRpc.invoke(null, jspUrl, null, null, true);
Java
A JSP page can call Java API code. Additionally, you can also call your own custom Java classes. Those classes need to be included with the zimlet in the form of a JAR file ("Java Archive"). The JAR file format allows you to bundle multiple Java files into a single file.
Using a JAR file with Zimlet Bundle
Your JAR file should be included in the root of your Zimlet Bundle ZIP. When you deploy your zimlet using the Administration Console (or via the Command Line), the JAR file Java classes will be deployed into the Zimbra server. You will need to restart your server for the Java classes to become available.
Using a JAR file with the Development Directory
If using the Development Directory, you need to manually copy the JAR file into place and restart your server for the Java classes to become available.
The location to copy the JAR file is: {zcs-install-dir}/jetty/webapps/zimlet/WEB-INF/lib
Note: Create the lib
directory if it does not exist.
Links to Examples
- Examples > Simple JSP (via Action)
- Examples > Simple JSP (via JavaScript Handler Object)
- Examples > Simple JSP (via HTTP GET)
- Examples > Simple JSP (via Ajax Asynchronous)
- JSP with custom Java classes