Calling a Java class from ASP

Output

Thu Dec 14 02:28:53 GMT-02:00 2017
4
2

Hello Geek

Isn't awesome that ASP can call Java classes with 'java:' moniker?! Yes, it is!!!

Sources

/java/Interop.class.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
	<head>
		<title>Calling a Java class from ASP</title>
		<!--// meta tags //-->
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
		<!--// link tags //-->
		<link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
	</head>
	<body>
		<div id="container">
			<div id="container-hd">
				<h1>Calling a Java class from ASP</h1>
			</div>
			<div id="container-bd">
 
<h2>Output</h2>
<div class="code"><pre><%
 
dim Java_Date, Java_Greeter
 
set Java_Date = getObject("java:java.util.Date")
Response.write( Java_Date.toString() )
Response.write( vbNewline )
 
Response.write( Java_Date.getDay() )
Response.write( vbNewline )
 
Response.write( Java_Date.getHours() )
Response.write( vbNewline )
set Java_Date = nothing
 
Response.write( vbNewline )
 
set Java_Greeter = getObject("java:hello")
Response.write( Java_Greeter.SayHello() )
Response.write( vbNewline )
set Java_Greeter = nothing
 
Response.write( vbNewline )
 
Response.write( "Isn't awesome that ASP can call Java classes with 'java:' moniker?! Yes, it is!!!" )
Response.write( vbNewline )
 
Response.write( vbNewline )
 
%></pre></div>
 
			</div>
			<div id="container-ft">
				<h2>Sources</h2>
				<h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
				<div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
				<h3>/hello.java</h3>
				<div class="code"><%= geshify( loadTextFile( Server.mapPath( "/hello.java" ) ), "java" ) %></div>
			</div>
		</div>
		<!--// javascript tags //-->
	</body>
</html>
 

/hello.java

public class hello {
 
    public static void main(String[] args) {
        //do nothing - this will keep us from getting a compile error
    }
 
    public String SayHello() {
        return "Hello Geek";
    }
 
}