Solved

calling java function from javascript without applet

Posted on 2002-04-29
15
404 Views
Last Modified: 2013-11-23
want to call java function from javascript which are in the same jsp page.
see the example below.

<%@ page import="com.dcx.mkt.webdaw.*,java.util.*" %>
<script>
function test1()
{
 alert("test");
 java.select();
 alert("test1");
}
</script>
<input type=text value="5" onchange="test1()">
<%!
protected void select()
{
System.out.println("testing java function");
}
%>
0
Comment
Question by:Amalanleon
  • 3
  • 3
  • 2
  • +5
15 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 500 total points
ID: 6978645
you can't... the select function is server-side where as your javascript is client side.  

maybe if you elaborate on what you are trying to accomplish by doing this, we can come up with a different solution.
0
 
LVL 35

Expert Comment

by:girionis
ID: 6978930
 You can call java methods from JavaScript but not in Servlets/JSP pages but only in Applets. See the following links:

http://developer.netscape.com/docs/examples/livewire/liveconnect_js_java.html
http://www.rgagnon.com/javadetails/java-0170.html
http://www.apl.jhu.edu/~hall/java/Java-from-JavaScript.html

  Hope it helps :-)
0
 
LVL 92

Expert Comment

by:objects
ID: 6979037
Easiest would be to convert your Java function to a Javascript function.
0
 
LVL 1

Author Comment

by:Amalanleon
ID: 6979311
Hi

I got  five Combobox, depeding upon the first Combobox selected value the remaining value will be filled. I can't hold all the data in my JSP because I got nearly 5000 records for each Combobox. I need a java function to call in my javascript OnChange event.

Amal
0
 
LVL 92

Expert Comment

by:objects
ID: 6979367
Then you'll need to use an applet, or invoke a new jsp page. The jsp and javascript are executed on different machines and cannot interact directly.
Also sounds like your applet is going to have to make a call to the server to get the values.
0
 
LVL 3

Expert Comment

by:rjackman
ID: 6979523
hi
there
simplest way is to get one record at a time
so that ur page displays the data for all comboboxes in 1 go
when selection is made onChange event is fired which will submit the page to servlet (typical MVC approach)servlet invokes the java bean that fetches the data for the required field
post it back to your JSP

cheers
RJ

0
 
LVL 2

Expert Comment

by:coreyit
ID: 6979543
If you could get by with supporting IE only, you might look into XMLHTTP. You could then use javascript to make a request for new content without leaving your current location.

-corey
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:iartmirko
ID: 6979708
Use a frame of size 0 to make a server call that retrieves the combo boy values of the second combo box. The HTTP result then returns a page containing a page with the values and a javascript function that fills the combo box in the other frame. The user won't see it because the frame is not visible.

I implemented this for a car seraching engine, where you first select the car's brand and than in a second combo can choose the name of the car, where the names are retrieved from a DB...

Mirko
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6979889
Amalanleon
You can call java from javascript using LiveScript.
Use <APPLET TAG> or <OPTION TAG> With  MAYSCRIPT as option. Then you can execute Javascript function in java or java in javascript.
The function in java should be public. And u need to be using arrays as ur input and output to the function. U need to use JSObject for this.
The classes are available in your netscape in java40.jar. Put this in path or archive in your applet.

Thanks
Shyam
0
 
LVL 2

Expert Comment

by:coreyit
ID: 6985171
"calling java function from javascript WITHOUT applet"
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6985505
Core
You should have applet. Without it no way you can do it.

Shyam
0
 
LVL 92

Expert Comment

by:objects
ID: 6985518
The question asks how to do it WITHOUT an applet.
Which infers they know how to do it WITH an applet.

:-)
0
 
LVL 35

Expert Comment

by:girionis
ID: 8682660
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- To be PAQ'ed and points NOT refunded

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0
 
LVL 35

Expert Comment

by:girionis
ID: 8682673
 Sorry, wrong suggestion (copied/pasted the wrong comment :-)), my suggestions actually is

- points to bobbit31

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Groovy:unable to resolve class error 2 65
mockito example issue 8 62
eclipse java  build path 6 43
fibonacci ten numbers 4 22
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now