To read the article online, visit http://www.4GuysFromRolla.com/webtech/080999-1.shtml

An Introduction to using Java with ASP
By Ian Stallings


Using ASP you can do a lot of cool stuff. But when the page views go through the roof it's time to move your code over to a more robust and mature programming language like C++, VB or ..you guessed it, Java. So in this article I've decided to give a brief introduction on how to use Java and ASP. In my next article, I plan on showcasing the true power of using ASP with Java by grabbing info from another website. With Java's hardcore networking capabilities, it'll be a snap. And when we're done we'll grab live stock info right from Nasdaq's website!

First, Let's start with what you'll need:

- Personal Web Server or IIS
- Microsoft's Java SDK 3.2 or higher
- Microsoft's latest Java Virtual Machine

Grab the latest of these from http://microsoft.com/java. Using these we can write the code right in notepad and compile the classes right from the command line. No wussy WSYWIG here.

Let's start coding! Open up notepad or any other text editor and dig in. Let's start with a "Hello Geek" example to get us started. Here's the 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"; } } //------------------------------------------------------------------

Ok, so far pretty simple? Now save your code into the same directory that jvc.exe exists (This should be in the Bin Directory under the SDK directory). Name the file hello.java. Now go the the command line and change directories to the same directory. At the prompt type

jvc hello.java

Note that the .java file must be the same name as the public class name (case sensitive) or you'll get an compile error.

In your bin directory now should be a file named hello.class. This is the compiled Java class file. Copy this into C:\Winnt\Java\TrustLib. Now we can access this class file from the ASP using the following code:

<% set javaObject = GetObject("java:hello") strResult = javaObject.SayHello() Response.Write(strResult) set javaObject = nothing %>

This wraps up the first part of the article. You'll see that writing a Java object and accessing it using ASP is really simple. And it's quick too! In the next article we'll really dig in and build a Java object that retrieves stock quotes right from the source! Pretty neat, eh? (Read the next article, Using Java & ASP to Grab Stock Quotes!)


Attachments:

  • hello.java in text format
  • hello.asp in text format


    Related Links:

  • http://www.microsoft.com/java
  • http://www.microsoft.com/downloads
  • Using Java and ASP to Grab Stock Quotes



  • Article Information
    Article Title: 4GuysFromRolla.com - An Introduction to using Java with ASP
    Article Author: Ian Stallings
    Published Date: Monday, August 09, 1999
    Article URL: http://www.4GuysFromRolla.com/webtech/080999-1.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers