Download IntegratedNETJavaWeb.zip - 4.21 KB
Introduction
This article describes how we can integrate Java with Microsoft Technology. Sometimes we may need an application where we integrate both technologies. I am writing this article keeping all beginners in mind, so they can learn something from it. This article describes how we can call some Java methods from .NET code, and pass some values to Java or .NET and vice versa. This is a simple ASP.NET application, which interacts with Java Applets while performing another operation. The application is very simple to do, but the main thing behind the scene is the idea and implementation logic.
Background
I have used two IDE for this Application
- Visual Studio 2005
- Eclipse
This digaram describes the main flow between Java nad .NET.
The main concept behind the scene is Applet, I have created a JAR file which contains one applet and I have called Java methods using applet from .NET. Once you get the data using JavaScript, it is up to you to decide how you going to use it on the server side.
Using the Code
First of all, we have to create a JAR file using Java. As I already explained, I have used Eclipse, just take a look the hierarchy of my Java applet and function.
I have created these methods and created a "Jar" file, named JavaNet.Jar. Now I am going to interact with this using .NET. The following is the Java Applet code.
public void WelcomeToJava()
{
JOptionPane.showMessageDialog(null,"Hi .NET Welcome To Java");
}
public String MessageForNetFromJava()
{
return "Hi .NET, Nice To Meet you !!";
}
public String MessageFromNETServerSide(String Message)
{
return "From Java : " + Message ;
}
Now, in the ASP.NET page, I have used an Applet
tag for invoking the applet. Now from the ID, MyJavaApplet
, I can call any Java methods from file.
The following is the JavaScript I'm using to call all Java methods
var ID= "<%=txtnum1.ClientID%>";
function btnCallJava_onclick()
{
MyJavaApplet.WelcomeToJava();
}
function btnNetMessage_onclick() {
var message=MyJavaApplet.MessageForNetFromJava();
alert(message);
}
function btnServerValueSend_onclick()
{
var Message= document.getElementById(ID);
var result=MyJavaApplet.MessageFromNETServerSide(Message.value);
alert(result);
}
OutPut
Call Welcome Message
Send Server Side Value To Java
Get Message From Java
Points of Interest
.NET and Java, both are leading the world's technology, and by integreting both of them we can do anything we want to do .