?
Solved

calling java methods from javascript

Posted on 2003-02-27
2
Medium Priority
?
145 Views
Last Modified: 2013-11-23
I would like to call a java funktion, which should return a list(vector, array etc.) of an objekt, or something else, containing a string and a URL, from javascript. How is this possible.
Can this be done without using applets, this is preferred.

Thanks..

Mr. Woods
0
Comment
Question by:darth_woods
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
boxy73 earned 225 total points
ID: 8035646
You must use an applet if you want to call java without giving control to a servlet, i.e, and going away from your page in the navigator.

Even if you use JSP pages with JSP code, this JSP is always compiled in the server first, and then, in the client, HTML and Javascript is run, so you cannot call from Javascript to Java code. You must use an applet to make that call. In this applet, you would use something like this:

URL con = new URL (url); //url would be a String with the URL of the servlet
URLConnection conAbierta=con.openConnection();
conAbierta.setDoInput(true);
conAbierta.setDoOutput(true);
conAbierta.setUseCaches(false);
conAbierta.setRequestProperty("Content-Type", "application/octet-stream");

ObjectOutputStream objSalida = new ObjectOutputStream(conAbierta.getOutputStream());

// Write in the channel
objSalida .writeObject(vectorContenido); //vector with your string that you wanna send
objSalida .flush();
objSalida .close();


and then receive it in the server and answer in the other way.


If the applet just implements that functionality, it would be really light.
0
 

Author Comment

by:darth_woods
ID: 8097596
i found out
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Introduction to Processes
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 5 hours left to enroll

765 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