在ASP中使用Java类(Using Java Classes from ASP)
|
admin
2010年7月7日 23:26
本文热度 5141
|
[p]using java classes from asp[/p]
[p]com components aren't the only way to use compiled code in your asp applications. if you're familiar with [br]java, but have no way of wrapping your classes as com objects (for example, you use jdk or j++ standard), [br]you can still use java from asp. and here's how[/p]
[p]first, make sure you have access to the c:
javatrustlib directory on your production server. [br]most shared hosting plans wouldn't allow this kind of access, but if you're developing an intranet, or a [br]site for dedicated server deployment, you'll be just dandy.[/p]
[p]next step, compile your java class as you would compile an applet or console class, using your favourite [br]compiler, any one will do, and remember to jot down the names of the public methods and properties your [br]class makes available.[/p]
[p]drop your class file into the trustlib folder, and make sure you have a recent java virtual machine [br]installed on the server. the latest ms version is here.[/p]
[p]now to call the class from your asp pages, use the following syntax[/p]
[p]set myjavaobject = getobject("java:classname")[br]so if you compiled your class as 'foobar.class', you use[/p]
[p]set myjavaobject = getobject("java:foobar")[br]generally, the performance of a java class used like this is slightly slower than a com dll, but faster [br]than just scripting, and you also have easy access to the inbuilt java class libraries, some of which [br]you'll find very useful in your asp apps.[/p]
[p]finally, call methods of the object as you would call methods of any other com component[/p]
[p]happy coding[/p]
该文章在 2010/7/7 23:26:36 编辑过