Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call java class from Javascript

Status
Not open for further replies.

Flimbo

Programmer
Joined
Mar 23, 2005
Messages
6
Location
FR
Hi
I'm trying to call a Java class from within my JavaScript and its not seeing the class. I have the class file in the same directory..so why can't it see it? What am I doing wrong?
 

How exactly are you trying to call a Java class from JavaScript?

Dan


The answers you get are only as good as the information you give!

 
yeah i'm crap at explaining things.. this is what I've done. My Java class is Stemmer and I need to use the stemWord method. Thought I should try and create a constructor?
What you think?

<html>
<head><title>JavaScript to Java Stemmer Example</title>

<script language="JavaScript1.2">

function swhandler()
{

var word = document.stemmer.word.value;
var stemObj = new Packages.Stemmer();
var stemmedWord = stemObj.stemWord(word);
document.stemmer.stemmedWord.value = stemmedWord;


<!-- Call Java Stemmer class.
-->


}

</script>

</head>

<body bgcolor = "white">

<!--
This is an HTML form that allows the user to enter data and allows JavaScript to
display the results it computes using a Java Stemmer Class back to the user.
-->

<form name="stemmer">
<table>
<tr>
<td>1)</td>
<td>Please insert word to be stemmed:</td>

<td>
<input type="text" name="word" size="20">
</td>
</tr>

<tr>
<td colspan="3"><input type="button" value="Stem" onClick="swhandler();"></td>
</tr>

<tr>
<td>2)</td>
<td>Stemmed Results:</td>
<td><input type="text" name="stemmedWord" size="20"></td>
</tr>

</table>
</form>
</body>
</html>
 
well how do you access them?

Kim
 

I'm not entirely sure if you can at all. Have you tried a Google search?

Dan


The answers you get are only as good as the information you give!

 
Yeap..all I found was stuff on JSObject or LiveConnect or using Applets and I don't think thats what I need, may be the LiveConnect part? I want to directly access and use my Java classes from my JavaScript code. I want to go from JavaScript to Java not Java to JavaScript. Do you have any ideas of what to try?

kimbo
 

Depending on what they do, you could recode your Java classes in JavaScript.

Dan


The answers you get are only as good as the information you give!

 
No I can't do that..because I will be needing to access alot of the Java classes I've already wrote so I wanted to figure the whole Javascript to Java communication thing out now if I can...any other suggestions? There has to be some way to do it?

kim
 

Try asking in the Java forum in case anyone there has had a similar requirement before.

As I said, I don't think it can be easily done (and certainly not in any cross-browser or cross-platform way).

Dan


The answers you get are only as good as the information you give!

 
K Dan thanks! I will try there.
Kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top