views:

84

answers:

5

when a button is clicked a textbox value needs to be sent to a java class so it can be processed . I've tried applets but failed ..i really could use some help here coz i'm stuck

help is much appreciated

Thanks =]

A: 

You can not call Java methods from Javascript.

You can, however, use Javascript to do a HTTP request to a server which will run the Java method for you.

Sjoerd
-1. You can call java methods of an applet.
josefx
@josefx - That's like saying "you can breathe in space........ except you need lots of specific and expensive gear".
Coronatus
+2  A: 

There is a better way to do it,

DWR is a Java library that enables Java on the server and JavaScript in a browser to interact and call each other as simply as possible.

DWR is Easy Ajax for Java

See the demo

DWR will generate the JavaScript to allow web browsers to securely call into Java code almost as if it was running locally. It can marshal virtually any data including collections, POJOs, XML and binary data like images and PDF files. All that is required is a security policy that defines what is allowed.

With Reverse Ajax, DWR allows Java code running on a server to use client side APIs to publish updates to arbitrary groups of browsers. This allows interaction 2 ways - browser calling server and server calling browser. DWR supports Comet, Polling and Piggyback (sending data in with normal requests) as ways to publish to browsers.

DWR provides integration with Dojo, TIBCO GI, Scriptaculous in the browser, and with Spring, Struts, Guice, Hibernate and others on the server.

org.life.java
this should put me back on track i think ...seems really straight forward Thanks =]
spiddan
You are welcome Daniel, you can always accept it as answer if its the case.
org.life.java
A: 

From Real Gagnon post, youc an always call a public method of the main class of an applet from javascript.

But nowadays, this kind of code has been deprecated in favor of REST calls to the Java server backend.

Riduidel
A: 

You know, that you have to create a Web-Application for that? You'll need an Application Server (e.g. Tomcat) for that. With a Web-Application, you can - roughly speaking - put the URL of an Action on the server into the action-Attribute of the form that contains your input box. The Action would be a Java-Class of a Method (depending on the Framework you use).

Have a look at the Java Servlet Specification or one of the countless Java Webapp Frameworks.

Ridcully
Well i'm new to this java-javascript interaction ,but thanks i should look into that
spiddan
A: 

I don't know where this Java is running. Is it in the browser, or is it on the server? If the server then you don't call anything directly, you use an asynchronous call of some kind to get a response - JSON, DWR, GWT RPC, Soap, Ad Hoc XML etc.

If the code is running in the browser as an applet then the Java Plugin provides entry points that allows Java to invoke JS and JS to invoke Java. The Java object could invoke a method in JS, passing it's own callback interface as a parameter. Once JS has that interface, two way communication is possible. A similar thing is possible with Flash and Silverlight too.

This document explains how - http://download-llnw.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/java_js.html

locka
it runs on the server ..thanks for your help
spiddan