Application of Cell plug-in J2EE system

Source: Internet
Author: User
In J2EE-based information systems, Java Applet with rich performance is an important form of interface layer. However, Java APIs have poor support for printing, and printing and outputting complex documents and reports requires a lot of work. The system described in this article solves this problem by introducing an ActiveX control-Cell plug-in. In this system, the interface is displayed by a Java Applet and printed and output by the Cell plug-in. The two communicate with each other through a set of Sun APIs.
1. Interaction between Java Applet and Ocx control
1.1 Access the Java Script method and Ocx control from a Java Applet
Sun provides an API for accessing Java Script from a Java Applet in JDK. This allows Java Applet to access DOM objects on HTML pages. This API is provided in the form of a Jar file: % JAVA_HOME %/jre/lib/jaws. jar, where % JAVA_HOME % is the directory where you install JDK. Add the jar file to the environment variable classpath, and you can use it to call from Java Applet to Java Script. The following is a code example for calling methods in Java Script:
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
public void init() {
JSObject win = JSObject.getWindow(this);
JSObject doc = (JSObject) win.getMember("document");
win.call("f", null);
}
}

In the above Code, win. call ("f", null) calls the method f () in JavaScript ().

1.2 access Java Applet from JavaScript
When using Java Plugin1.4.x to run a Java Applet, you only need to regard the method in the Java Applet as the method of the Java Plugin control and call it directly in Java Script. The following is a simple example:
(1) In the Object tag loaded with Java Plugin, specify a name with the parameter ID:

<OBJECT ID="MyPlunin" WIDTH=500 HEIGHT=120
CLASSID="CLSID:8AD9C840-044E-11d1-B3E9-00805F499D93">
<PARAM NAME="code" value="MyApplet.class">
...
</OBJECT>

(2) Add a button on the HTML page and click it to call the method in Java Applet from Java Script:

  <input type="button" name="Button1" value="Start"
onClick="calculate" language="JavaScript">

 

(3) assume that your Java Applet is MyApplet. java and has a public method method1 (), you can directly call this method using the following Java Script code:

<SCRIPT language="JavaScript">
function calculate() {
document.. MyPlunin.method1()
}
</SCRIPT>

Ii. Cell plug-in Introduction
The Cell plug-in of table Hua is an ActiveX control that functions very similar to Excel and is used for Web development. It can display, edit, and print tables in a Windows browser.
Iii. System implementation
3.1 system architecture

Figure 1
Figure 1 shows the system configuration. As shown in the figure, this is a typical layer-3 application system. In this system, the Java Applet and Cell plug-ins are deployed on the Web Server. During running, they are downloaded to the client and run in the browser.

Figure 2 shows the operation of the system. As shown in the figure, the Java Applet running on the client accesses the EJB on the application Server through the Servlet on the Web Server and interacts with the background. As the presentation layer, Java Applet displays the interface on the client.
To print the output, the Java Applet sets the data and display format to the ins, and calls the ins to print and view the ins to complete the printing function.
3.2 use the Cell plug-in to print the Java Interface
3.2.1 embed the Cell plug-in of table China on the HTML page
To call the Cell plug-in of table Hua in the Applet interface, we first hide a Cell plug-in on the HTML page:

<OBJECT classid=clsid:3F166327-8030-4881-8BD2-EA25350E574A 
id=DCellWeb1 style="HEIGHT: 0px; WIDTH: 0px">
<PARAM NAME="_Version" VALUE="65536">
<PARAM NAME="_ExtentX" VALUE="14902">
<PARAM NAME="_ExtentY" VALUE="6075">
<PARAM NAME="_StockProps" VALUE="0">
</OBJECT>

Use style = "HEIGHT: 0px; WIDTH: 0px" to specify that the HEIGHT and WIDTH of the Cell plug-in are both 0, so as to hide the Cell plug-in.
3.2.2 provide two interface calling methods in the Applet
The following is an example of the Applet code, which provides the callCellMethod () and callJavaScriptMethod () interface methods, which can be used to call the Cell plug-in method and JavaScript method respectively:

public class MyApplet extends javax.swing.JApplet {
private JSObject win = null;
private JSObject cell = null;

public Object callCellMethod(String name, Object[] params) {
return getCell().call(name, params);
}

public Object callJavaScript(String name, Object[] params) {
return getJSwin().call(name, params);
}

private JSObject getCell() {
if (cell == null) {
try {
JSObject doc = (JSObject)getJSwin().getMember("document");
JSObject all = (JSObject)doc.getMember("all");
cell = (JSObject)all.call("item", new Object[]{"DCellWeb1"});
}
catch (Exception e) {
e.printStackTrace();
}
}
return cell;
}

private netscape.javascript.JSObject getJSwin() {
if (win == null) {
win = netscape.javascript.JSObject.getWindow(this);
}
return win;
}
}

Through the getCell () method, you can directly obtain the Cell plug-in represented by JSObject in the Java Applet, so that you can directly call its method. For example, to write data to a Cell of the Cell plug-in a Java Applet, you can call the following:

Integer row = new Integer(1);
Integer column = new Integer(1);
Integer page = new Integer(0);
callCellMethod("SetCellString", new Object[]{column, row, page, “str”});

SetCellString is the interface method provided by the Cell plug-in. In this way, the Cell plug-in from Java Applet to table China is called.
Iv. Conclusion
In this application system, we only use the print preview and print functions of the Cell plug-in, without using it for screen display. All the print formats and data are prepared in the Java Applet. The Cell plug-in sets the format and data for the Cell plug-in. The Cell plug-in completes the paging and printing functions.
This is a way of separation of performance and data: in Java Applet, only print data is organized, and all the print performance work is handed over to the Cell plug-in, which can greatly reduce the workload.
In addition to the printing function, the Cell plug-in also has very powerful functions such as input, display, editing, and chart. It can produce very complex reports. Using the Cell plug-in, you can also export data to files in Excel or PDF format.
 

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.