redoakgroup2
Programmer
Hi,
I am attempting to write a simple JDBC application that finds a returns the closest dealership for a given zip code. Not only do I need to return the dealership ID, but also the id of a contact at that particular dealership (as well as his/her name and email). I have written this and tested it on my local machine via the command prompt and all is well. I wrote this code because I reading JavaScript: The Definitive Guide by David Flanagan, I discovered that you can call java methods via JavaScript. I am attempting to do this right now and failing miserably. I have searched the web looking for a good tutorial to no avail. I even found a good code snippet that works, but I cannot translate it to work for me. I guess the easiest thing would be to show the code...
Here is my html:
and my java looks like this:
... and so on.
I have many questions. One, obviously, where does my code go wrong? Two, does the code I call need to be an applet? Three, the method I am trying to call takes a string array of arguments (zip, radius, etc.), so is it possible to pass an array of arguments? Four, in the end, the goal for me is to return a DealerLocator object to a javascript object, and read all the values from there. Is this possible? I would appreciate any help on this matter. Any help would be great, and thank you in advance.
I am attempting to write a simple JDBC application that finds a returns the closest dealership for a given zip code. Not only do I need to return the dealership ID, but also the id of a contact at that particular dealership (as well as his/her name and email). I have written this and tested it on my local machine via the command prompt and all is well. I wrote this code because I reading JavaScript: The Definitive Guide by David Flanagan, I discovered that you can call java methods via JavaScript. I am attempting to do this right now and failing miserably. I have searched the web looking for a good tutorial to no avail. I even found a good code snippet that works, but I cannot translate it to work for me. I guess the easiest thing would be to show the code...
Here is my html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="JavaScript">
var browser = new String(navigator.appName);
var version = parseInt(navigator.appVersion);
function GetName()
{
var myApplet=document.getElementById("sample3")
alert(myApplet.name)
alert(myApplet.getData())
}
</script>
</head>
<body>
<applet name="sample3" mayscript="true" id="sample3"
code=DealerLocatorApp
height=10
width=10>
</applet>
<script language="JavaScript">
if (browser == "Netscape") {
var getVarValue = new Function( "str",
"return Packages.DealerLocator.getData(str);");
}
else if (browser == "Microsoft Internet Explorer") {
var getVarValue = new Function( "str",
"return document.sample3.getData(str);");
}
else document.writeln( "Unsupported Browser " + browser + " " + version);
</script>
<script language="JavaScript">
var args = ['3000', '1', '60062', 'sportle@redoakgroup.com', 'gw_lm_dev'];
document.write(getVarValue("test"));
</script>
<!---
<form name="myForm" method="post" action="">
<input type="button" name="Button" value="Button"
onClick="GetName()">
</form>
--->
</body>
</html>
and my java looks like this:
Code:
import java.sql.*;
import java.io.*;
import java.util.ArrayList;
public class DealerLocator extends java.applet.Applet
{
private int radius = 0;
private int prodline = 0;
private double longitude = 0;
private double latitude = 0;
private double rlongitude = 0;
private double rlatitude = 0;
private String zip = "";
private String email = "";
private String dealerID = "";
private int dealerContactID = 0;
private String dealerContactEmail = "";
private String dealerContactFirstName = "";
private String dealerContactLastName = "";
private static DealerLocator locator;
public DealerLocator(int radius, int prodline, String zip, String email)
{
this.radius = radius;
this.prodline = prodline;
this.zip = zip;
this.email = email;
}
private static DealerLocator getDealer(DealerLocator locator, Statement stmt) throws SQLException, IOException
{
I have many questions. One, obviously, where does my code go wrong? Two, does the code I call need to be an applet? Three, the method I am trying to call takes a string array of arguments (zip, radius, etc.), so is it possible to pass an array of arguments? Four, in the end, the goal for me is to return a DealerLocator object to a javascript object, and read all the values from there. Is this possible? I would appreciate any help on this matter. Any help would be great, and thank you in advance.