This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Java in General and the fly likes Calling .js file from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling .js file from Java" Watch "Calling .js file from Java" New topic
Author

Calling .js file from Java

Shailendra Suryawanshi
Greenhorn

Joined: May 13, 2008
Posts: 9
Is there any way we could call Javascript function in a .js file from Java?


Shailendra Suryawanshi<br /> <br />[SCJP 6]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

Are you asking about Java running on the server (as part of a servlet or JSP), or as an applet on the client.

if the former, no. Please read this article to understand why.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shailendra Suryawanshi
Greenhorn

Joined: May 13, 2008
Posts: 9
My expectation is to call a javascript function in a .js file from a normal Java class file.

I don't want to call it from jsp/servlet or applet.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

Without a servlet, JSP or applet, how do you expect to run this Java class as part of the web application?
Shailendra Suryawanshi
Greenhorn

Joined: May 13, 2008
Posts: 9
It's not a web application.

I've a BPM studio which has the ability to call Java classes.

Now I wish to invoke javascript from this Java class, which now I guess is not possible.

Please comment.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
The Rhino library lets you run JavaScript scripts from within regular Java classes. There was an article about that in the JavaRanch Journal last year.


Ping & DNS - updated with new look and Ping home screen widget
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

Ah, you should have mentioned that. Most questions here are related to web apps. I've moved this to a general Java forum.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calling .js file from Java
 
Similar Threads
Java embedded in .JS file not working
Calling .js from another .js
configure tomcat to accept embedded java in .JS file
embedding Java inside html/,js file not working
interpret java code <% ..%> in .js file