开发者

Calling JavaScript methods from Java

I have a webpage that has JavaScript in it. The script contains a method that updates the webpage. I also have a java UDP server. When I get some parameters from a client, I want to call开发者_StackOverflow the method in the javascript to update the page.

Is it possible to call methods in Javascript from Java source code? Any pointers?

Thanks!

EDIT: For Ajax, the "request" initiates from the webpage. I want something that can change the webpage by itself - without this request.

A more succinct question would be: Can I dynamically update a webpage from java source file?


In order to reading javascript result you need a browser runtime AFAIK (You cannot get javascript result through a raw socket). You have to include a browser (JTextPane should be able to do it) into your udp server.


DWR is the answer, but it seems dead with no progress for some months. I don't think so you can directly call JavaScript methods from Java without passing an Asynchronous call using Ajax.

I have no idea on how you would dynamically change your content of webpage without an request being passed.


This is what we wanted to do: -Send co-ordinates from an android phone to a server -Plot these on a map in a browser window

The complexity was - One 'box' was server for android, and client for google maps. And we needed some glue between these two functionalities.

We initially tried ActiveMQ but could not get it to work.

Due to time constraints, we were forced to explore other approaches... our end result isn't elegant, but it works.

We have a FIFO on the server to which the co-ordinates are written. On the same server, our map page is also hosted. On a button press, XMLHttpRequest is sent to the server. In response, a co-ordinate is dequeued and sent back, which is plotted on the map using google maps api.

I will be happy to share more details/answer questions...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜