When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Monday, August 09, 1999

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!

- continued -

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


    Ian Stallings is a 26 year old Software Engineer from the Washington DC area. He has experience in Internet/Intranet development using ASP, VB, Java, SQL Server, and IIS. Prior to devoting his career to application development he worked as a systems administrator at a small ISP.

    When not developing applications or tinkering with computers, he masquerades as a normal human being


  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article