Use com components in jsp programs

Source: Internet
Author: User

There are not many opportunities to use com components in jsp programs, and jsp does not directly operate on com functions, but sometimes some work must be completed using com components, the following describes the specific operation methods.
There are two methods to use com components in jsp: one is to use javascript to control on the client (strictly speaking, this should be an html function), such:

<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;
}
</Scept>

Return result: Hello, Li zongbin

However, this method has the disadvantage that it can only be operated on the client, but not on the server. In addition, each client must install this component before it can run.
The second is to directly use jsp to connect to JACOB bridge through Java-COM to operate the com component on the server. JACOB's website is http://danadler.com/jakb /. Two files are required for running: jacob. jar and jacob. dll.
The configuration method is: Put jacob. jar in CLASSPATH and add the path of jacob. dll to path. Such as d: \ com

The method is as follows:

1. Register com components on the server first;
2. Find the component name (generally known, go to the registry if you do not know );
3. Program example:

<% @ Page contentType = "text/html; charset = gb2312" language = "java" %>
<% @ Page import = "com.jacb.com. *" %>
<% @ Page import = "com. jacob. activeX. *" %>
<%
System. runFinalizersOnExit (true );
ActiveXComponent mf = new ActiveXComponent ("MakerCom. MakerExt"); // locate the component
Object myCom = mf. getObject (); // generate an Object
String result = Dispatch. call (myCom, "Hello", new Variant ("Li zongbin "));
/* Call the component method. myCom is the Component Object Name, Hello is the component function, and new Variant ("Li zongbin") is the component parameter variable, if there are multiple, you can add them at the back end. The method is the same */
Out. println (result );
%>

Related Article

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.