简体   繁体   English

从Java运行JavaScript?

[英]running JavaScript from Java?

very new to coding and decided to start a project of mine. 对编码非常陌生,因此决定启动我的一个项目。 I watched a video on how to get it set up and started but after tinkering with it a little, I realized it was Java, not JavaScript. 我观看了有关如何设置和启动它的视频,但是在稍微修改一下之后,我意识到它是Java而不是JavaScript。 (Hey, i'm a noob at this) and I wanted an easier way to implement new things. (嘿,我对此很陌生),我想要一种更简单的方法来实现新事物。 this is what my main script looks like. 这就是我的主要脚本。

public void onMessage(String Message){
if(message.equals("Apples"){
sendMessage("You said apples!")}
else { 
if(message.equals("Oranges" //any text 
){
    sendMessage("you said Oranges and" //what they put for any text
)
 ...

Is there a way to take the bit that says Oranges and replace it by calling a JS function from another file? 有没有办法采用表示Oranges的位并通过从另一个文件调用JS函数来替换它的方式?

Java and javascript are two completely different things. Java和javascript是完全不同的两件事。 Java is a full programming language while Javascript is used to make websites dynamic , so it works inside a webbrowser. Java是一种完整的编程语言,而Javascript用于使网站动态化,因此它可以在Web浏览器中使用。 You should figure what you want and make a choice. 您应该弄清楚自己想要什么,然后做出选择。

As others said, you need to figure out what you want. 正如其他人所说,您需要弄清楚自己想要什么。

Nevertheless, it is possible to run Javascript in java. 不过,可以在Java中运行Javascript。 Check javax.script package and check the docs: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#evalfile 检查javax.script程序包并检查文档: http : //docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#evalfile

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM