Invoking Java-written classes in Asp/asp.net

Source: Internet
Author: User
Asp.net|asp.net occasionally encounters in asp/asp during the development process. NET to implement functionality that was previously implemented in Java, the following is a simple example of how to use this detail:

1. Create Java files:
Use any editor you like to edit the following:
public class Hello
{
public string HelloWorld (string s)
{
if (s = = null)
Return "";
Else
return s;
}
}
Save this file as a Hello.java

2. Compile Java file as class:
Command mode run: Javac Hello.java

3. Copy the compiled Hello.class file to the C:\winnt\java\trustlib directory.

4, create the following file, named Test.asp:
<%
Set javaobject = GetObject ("Java:hello")
msg = Javaobject.helloworld ("Hello World")
Set javaobject = Nothing
Response.Write msg
%>

5, testing:
Create a virtual directory in IIS test, copy test.asp files to this virtual directory, restart IIS, Access http://localhost/test/test.asp in IE, the page displays "Hellow World", indicating success of the call.

ASP.net can be used in the same way as the ASP.

Note: Step 2 compile with a 1.3.x compiler, in 1.4 of the JDK is normal, but I call in Asp/asp.net Show no object for moniker error

6. If you import other jar packages in the Java file, you will need to copy these. jar files to the C:\winnt\java\packages directory in step 3, and--> the Advanced--> system variables in My computer's--> properties, Add the classpath variable whose value is the detailed path to the jar file, such as C:\winnt\java\packages\ldapfilt.jar;c:\winnt\java\packages\ldapjdk.jar;c:\winnt \java\packages\ldapsp.jar;. Separated by semicolons in the middle, end with a decimal point

Above in both Chinese and English Win2000, WinXP test pass




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.