There are not many opportunities to use COM components in JSP programs, and JSP does not have functions to directly operate COM, but some work sometimes must be completed using COM components. Let’s talk about the specific operation methods.
There are two ways to use com components in jsp: one is to use javascript to control it on the client (strictly speaking, this should be a function of html), such as:
<OBJECT id="myCom" classid="clsid:9D8A2E2F-D38F- CDAC-D0C5-5B3FB2275442" codebase=".com/com.cab#version=1.9.9.0" >
</OBJECT>
<script>
function Hello() {
var result= myCom.Hello("Li Zongbin");
return result;
}
</scipt>
Result returned: Hello, Li Zongbin.
However, this method has a drawback: it can only be operated on the client side and cannot operate on the server side. And each client must install this component to run.
The second is to directly use jsp to operate the server-side com component through the Java-COM connection bridge JACOB. The download address of JACOB is http://danadler.com/jacob/ . Two files are required to run: jacob.jar and jacob.dll.
The configuration method is: put jacob.jar in CLASSPATH, and add the path where jacob.dll is located to path.
the method used for
d:com
is as follows:1. First register the com component on the server side;
2. Find the name of the component (usually you should know it, if you don’t know it, go to the registry to find it);
3. Program example:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="com.jacob.com.*" %>
<%@ page import="com.jacob.activeX.*" %>
<%
System.runFinalizersOnExit(true);
ActiveXComponent mf = new ActiveXComponent("MakerCom.MakerExt");//Find the component Object myCom = mf.getObject();//Generate an object String result= Dispatch.call( myCom, "Hello", new Variant( "Li Zongbin" ) ) ;
/*The method of calling the component, myCom is the object name of the component, Hello is the function of the component, new Variant("Li Zongbin") is the parameter variable of the component, if there are more than one, you can add them at the end, the method is the same*/
out.println(result);
%>