简体   繁体   English

Java检测字符串是否为有效的JS脚本

[英]Java detect if a string is a valid JS script

I want to detect if a string is a valid javasript code for pass it for the evaluation of rhino engine, now i'm assuming that the string is a javascript script with this simple statement : 我想检测一个字符串是否是一个有效的javasript代码,以便将其传递给Rhino引擎评估,现在我假设该字符串是一个带有以下简单语句的JavaScript脚本:

if(jsString.trim().endsWith(";")) {
//Evaluate with Rhino
}

Is there a better way for figure out if a string is a valid JS script ? 有没有一种更好的方法来确定字符串是否是有效的JS脚本?

What is the best way ? 什么是最好的方法 ?

You could utilise something like: http://code.google.com/p/jslint4java/ 您可以利用类似的方法: http : //code.google.com/p/jslint4java/

In any case, you want to run the string through JSLint. 无论如何,您都希望通过JSLint运行该字符串。

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

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