Javascript Using Java Methods
Jul 23, 2005Can Java classes/objects be used from within the javascript code on the
HTML page? I.e., can I call a Java method from the javascript function?
Can Java classes/objects be used from within the javascript code on the
HTML page? I.e., can I call a Java method from the javascript function?
The javascript fails to call an embeded applet's function. In the javascript
console, it shows "Error XXXX is not a function". Following are some parts of my code.
if(parent.document.cpmApplet){
parent.document.getElementById('cpmApplet').refreshCPMApplet();
}
if(parent.BottomIframe.document.resultApplet){
parent.BottomIframe.document.getElementById('resultApplet').refreshTableApplet ();
}
Here parent.document.cpmApplet and parent.BottomIframe.document.resultApplet are valid since I loaded both the applets with the same name using <APPLET> tag for Netscape/Mozilla and OBJECT tag for Windows.
The issue is with Netscape and Mozilla on Unix platforms only. I would appreciate if anyone could help me to solve this.
in JSP, it's easy to pass value from java-variable to
javascript-variable, like
js_function(a)
{ a=<%java-class.A%>
}
I'm wondering how is the other way around? I tried
js_function(a)
{ <%java-class.A=%>a
}
but there was compiling error.
Is DHTML a language? or is it a composition of JavaScript and css? Does Java(not javascript) has something to do in it?
What is actually the best to create client-side dynamic pages?
I know JAVA is used to create applets but I am not sure of wich is the most powerful....
Also, wich are the newer versions of all the above languages?
I am a XHTML/CSS developer with an interest in AJAX. I am at the stage were I wish to learn how it's all done.
So my quesiton is this:
To develop AJAX applications do I need to learn JAVA or Javascript?
It may sound like a dumb question considering AJAX is mainly javascript and XML, however will learning JAVA first off be a benefit?
I am trying to call a java method from within my Javascript, but cannot
seem to get it to work. All the examples I have found online and in
the forums are using Java applets. I have a method that I want to call
that does a search, and produces a message dialog displaying the
results. Also, the class file lives next to the html file. How would
I invoke this in my code? This is what I have now:
<script>
function searchStrings(){
Searcher.search();
}
</script>
<form>
<input type="button" value="Search" onclick=searchStrings()>
</form>
This may be more of a Java question, but I feel that JavaScript experts
may be more qualified to help me find a solution.
In short: is it possible to call a Java method from JavaScript, passing
as an argument a JavaScript array (in my case, an array of doubles)?
Supposing I have array x containing only doubles, I have tried:
document.MyApplet.myMethod(x);
But the method only ever seems to receive "null" as an argument.
Conversely, if I try this with a String, or a single character, or
almost anything else, there isn't a problem. Any ideas?
let's me explains my long problem:
I'm doing an intranet with a media part. So im must be able to upload files on
a ftp server AND have a record of informations about this file and meta date in
a MySQL database, shown in a php page.
So the first thing i was doing was:
1/ * A HTML Form, with a <input type="file"> which was uploading the file to
the web server. And then, in the next action-php-page, using ftp functions from
php to upload to the ftp server. But this make upload the file 2 times, which
slow, and the user can't do anythig except waiting in front of a blanck loading
page.
=> no way
(BTW, the site admin refuse that the ftp server and the web server to be the
same computer)
So i tried something else:
2/ * A HTML form, the user enter meta data about the media, click next, and
then, a php page which loads a java applet an pass informations to it (by param
tags).
The applet have a browse button, and a go button, which start the transfert
(JDK 1.4.1) trough the URLConnection. The file is uploaded once, and there is a
progress bar, which is wonderful.
But now, i need the src_file information wich is the java applet. So i have two
options:
A/ I make a post to the webserver from the applet. But i'm using session
identification (needed for tracing users actions) and i'm gonna use SSL in less
than one month, so i think it would be complicated.
B/ I export the information from the java applet to javascript, and then to
HTML hidden field, so that the user can submit the full-hidden-filled form. But
i can't make LiveConnect works.
i'm under Mac OS X 10.2 (jaguar) so i need to make work LiveConnect on both
Safari 1.0 (v85.6), mozilla 1.5, and Mac OS IE (5.2).
Can you call a java class from within a javascript?
View 1 Replies View RelatedA Java applet has two methods stop() and destroy() that get called when the user moves to a different page. Does javascript have anything similar?
View 2 Replies View RelatedI am writing a java application as a mozilla extension.
Because mozilla uses javascript for the frontend,
i need the javascript to call my external java application
and pass one parameter to it.
Can anyone help me how to set default website as homepage in mozilla using java/ javascript.
Following javascripts code works in IE but not in Mozilla.
<input type="button" value="Set Default" onClick="this.style.behavior='url(#default#homepage)'
this.setHomePage('http://www.myDefaultWebsite.com')">
I am looking at a client’s site that has a scrolling text bar at the bottom of the page for latest news. I have been asked to recommend whether they keep the scrolling text as a java applet or whether they make it dhtml with Javascript to make it scroll.
To be honest, I’m not sure whether there really is an important difference, in terms of download time, likelihood of working (if client browsers are better enabled for one verses the other), or whether there are any other reasons one should be used over the other.
I have a javascript function that needs to access methods of a java
object(localTag). In my JSP I'm trying to include hidden fields for
the Strings returned from the getter method calls of the object like
so:
<html:hidden name="FrmCustomerHolding" property='<%=
"localTag.getTagName()" %>' />
<html:hidden name="FrmCustomerHolding" property='<%=
"localTag.getTagValue()" %>' />
If I can do something like this, what is the correct syntax and how do
I access this property in my javascript? When I have a hidden field
that is just a String, I access it in the javascript like
"document.getElementById("theString").value" and it works fine, but I
can't seem to find how to access the String value of a method call.
I am wondering if it is possible to get the response from a method
within a given page, and that function alone? Traditionally, I have
been getting the response from the Page_Load method of the targeted
page, but now I want the response from a particular method on the
target page:
Public Sub SomeCallback(ByVal sender As Object, ByVal e As EventArgs)
'RETURN XML FOR CALLBACK
End Sub
When you use addEventListener (or addEvent in IE) to call an object
method, does it call it with the correct this parameter?
The ECMAScript reference has a lot to say about the caller using
Function.prototype.call or Function.prototype.apply and passing the
correct this pointer for the context, but how does addEventListener
determine the correct this pointer. Or does it just punt and pass the
global context, thus making it impossible to refer to the object this
in an object method used as an event listener?
About when to use setter methods. For example, I have this code
Should this be used like this:
I think a better question is when to use the .each loop? Since, the first line of code I have works fine.
So I have this homework assignment where I need to get my application from switches to using methods to give me the same result. I usually am good in this class, but right now I am completely lost. Here is a piece of the code using switches:
/* Get Type of Math problem from the user */
input = JOptionPane.showInputDialog(null,"Enter the type of Math Problem"
+ "you would like to solve:
"
+ "Addition = 1
"
+ "Subtraction = 2
"
+ "Multiplication = 3
"
+ "Division = 4
"
+ "Enter the number of your choice: "); .....
I need to get this same result by using methods. I can use these method signatures:
public static int readProblemType(){}
public static int getAddProblem(int randomValue1 int randomValue2){}
public static int getSubProblem(int randomValue1 int randomValue2){}
public static int getMultProblem(int randomValue1 int randomValue2){}
public static int getDivProblem(int randomValue1 int randomValue2){}
public static int readAnswer(){}
Looking at what I need to do, how would I use public static int readProblemType(){} method to read the problem type? Or where should I start?
Programming assignment: Write a program for analyzing El Paso weather. This program must allow the user to enter dates followed by temperatures at these dates. Assume that we are only tracing one year, so the overall number of such dates does not exceed 366. Your must then output the following information:
*the average temperature;
*the list of all the days when the temperature was below freezing (i.e., below 32);
*the hottest temperature, and the list of all the days when the temperature was the hottest.
Main difference: In the previous assignment, following our advise, you stored the dates in one array (array of strings), and temperatures in another array (array of numbers).
For this new assignment, define a class Record whose objects contain two fields:
*a field date that contains the date, and
*a field temperature that contains the temperature.
Instead of using two arrays, use a single array of records (i.e., of objects of type Record).
The problem I'm having, is that I do not know how to read from two files and store the information into one array. (For example: with this assignemnt, I need to have one array with 366 fields, and in each field there needs to be a date and temperature.)
I have more of a programme design related question here: I have an object with 2 methods, those two methods are supposed to be called repeatedly one after the other (e.g. by setInterval())
window.setInterval(function() {
obj.method1();
obj.method2();
}, 100);
the problem with this code is that the execution time of those methods may increase depending on the processed data (an array with several hundred elements or more) so it may be, that the execution time of both methods exceeds the given repetition time. I could solve that by placing a call to the next function in each method, but I wonder if that is good design or not (tight coupling)
code for method2() is analogue
Obj.prototype.method1 = function ()
{
/* working code here */
[Code]....
How are methods masquerading as properties? Does this make methods more flexible as objects or plain functions?
View 6 Replies View RelatedI pulled out an old javascript object I created a while back a few days ago and I've been developing in Firefox ever since. Then I decided to test how it worked in other browsers and.....it works in none of them! Not chrome, not IE(7/8), not opera, and not safari.
It's built like this:
Code:
function myCalendar() {
//constructor function
}
myDiv.prototype.newMethod = function() {
[Code].....
It's really as simple as that....what's on the go? Do any JS experts out there know anything about this?
When a custom object is created in javascript, then methods need to be defined for this object. Still every object has toString() method available to them, even if it is not defined. How is this method available to all the objects ? Is it inherited from some root object ?
Is sort() method available to all the objects ? What are the other methiods available to all objects ? Where can I get list of available methods ?
Creating methods that can be used by all elements?
View 1 Replies View RelatedI am a little confused how the memory for objects is allocated in
JavaScript. David Flanagan, in "javascript: The Definitive Guide,"
states that each property of a class takes up memory space when
instantiated. So space is created for aMethod three times in this
example: Code:
I just wanted to know if there was any way to use script to display a
list of methods linked to a particular object? The object I have in
mind is getBrowser(), and I can't seem to find any documentation online
with regards to it's methods.
Also, as I am learning, it would be nice to be able to know what
methods are available for a particular object/function, without
necessarily having to spend a while looking up an object's method when
it's documented in a lot of different places, but only vaguely.