File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android 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: 60794
    
  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: 60794
    
  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: 41137
    
  45
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 - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Ah, you should have mentioned that. Most questions here are related to web apps. I've moved this to a general Java forum.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling .js file from Java
 
Similar Threads
Java embedded in .JS file not working
interpret java code <% ..%> in .js file
Calling .js from another .js
configure tomcat to accept embedded java in .JS file
embedding Java inside html/,js file not working