[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 146
  • Last Modified:

calling java methods from javascript

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.


Mr. Woods
1 Solution
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.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.
darth_woodsAuthor Commented:
i found out

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now