Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Java in General and the fly likes Calling .js file from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply 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: 56229
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56229
    
  13

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: 35257
    
    7
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.


Android appsImageJ pluginsJava web charts
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56229
    
  13

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Calling .js file from Java
 
Similar Threads
Calling .js from another .js
configure tomcat to accept embedded java in .JS file
Java embedded in .JS file not working
embedding Java inside html/,js file not working
interpret java code <% ..%> in .js file