‘壹’ java的脚本语言是指什么
java的脚本语言就是jsp(Java Server Page)服务器动态页面语言
jsp语言是嵌入在Html文档中的java代码
jsp语言语法格式如下:
<% Java代码 %>
<%
//1 定义变量 2 编写语句
%>
<%!
//2 定义全局变量 2 方法 3 类
%>
<% =输出变量或字符串常量 %>
你明白了吗?
‘贰’ java,怎么用脚本运行
1.直接执行Python脚本代码
引用 org.python包
1 PythonInterpreter interpreter = new PythonInterpreter();
2 interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); "); ///执行python脚本
2. 执行python .py文件
1 PythonInterpreter interpreter = new PythonInterpreter();
2 InputStream filepy = new FileInputStream("D:\\demo.py");
3 interpreter.execfile(filepy); ///执行python py文件
4 filepy.close();
3. 使用Runtime.getRuntime()执行脚本文件
这种方式和.net下面调用cmd执行命令的方式类似。如果执行的python脚本有引用第三方包的,建议使用此种方式。使用上面两种方式会报错java ImportError: No mole named arcpy。
1 Process proc = Runtime.getRuntime().exec("python D:\\demo.py");
2 proc.waitFor();
‘叁’ 如何在java中调用按键精灵脚本
采用java Robot类可以实现你的需求,
Robot类的操作是基于坐标的,可以进行点击、输入等操作。
具体请查阅Robot类帮助。
‘肆’ Java里的脚本语言怎么写
你是说js还是要怎么样啊..你问得这么官方
‘伍’ 如何在java中执行shell脚本
1、最常用的方法:
Processp=Runtime.getRuntime().exec(SHELL_FILE_DIR+RUNNING_SHELL_FILE+
""+param1+""+param2+""+param3);
intrunnngStatus=p.waitFor();
2、通过ProcessBuilder进行调度,这种方法比较直观,而且参数的设置也比较方便:
ProcessBuilderpb=newProcessBuilder("./"+RUNNING_SHELL_FILE,param1,
param2,param3);
pb.directory(newFile(SHELL_FILE_DIR));
intrunningStatus=0;
Strings=null;
try{
Processp=pb.start();
try{
runningStatus=p.waitFor();
}catch(InterruptedExceptione){
e.printStackTrace();
}
}catch(IOExceptione){
e.printStackTrace();
}
if(runningStatus!=0){
}
return;
参数说明:
RUNNING_SHELL_FILE:要运行的脚本
SHELL_FILE_DIR:要运行的脚本所在的目录; 当然你也可以把要运行的脚本写成全路径。
runningStatus:运行状态,0标识正常。 详细可以看java文档。
param1, param2, param3:可以在RUNNING_SHELL_FILE脚本中直接通过1,1,2,$3分别拿到的参数。
‘陆’ 在java中执行javascript脚本有什么意义实际项目中有何应用难道是实现类似于规则引擎之类的么
把js做们一种脚本语言来潜入的话,就相当于潜入了lua类似的脚本语言,以后可以通过修改js来修改业务逻辑
‘柒’ 使用java怎么写一个shell脚本
java-cp"./classes:./classlib"-Dparam1=zzzzztest.myclass$0
-cp指定classpath
-D指定一个参数,程序内用System.getProperty("param1")访问
$0把外部调用的参数传递给javaclass
‘捌’ java程序中运行js脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
public class ExecJs {
/**
* 记录日志类
*/
private Logger log = Logger.getLogger(ExecJs.class);
/**
* 后置处理,执行js脚本
* @param js
* @throws Exception
*/
public void execJs(String js, Map<String,Object> map) throws Exception {
if (log.isDebugEnabled()) {
log.debug("execJs js : " + js);
Iterator<Entry<String, Object>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object> entry = (Entry<String, Object>) it.next();
log.info("EXECJS MAP : " + entry.getKey() + "---" + entry.getValue());
}// end while
}// end if
if ("".equals(js) || js == null) {
log.info("EXECJS ERROR : JAVASCRIPT CONTENT IS NULL");
} else if(map == null || map.size()<=0){
log.info("EXECJS ERROR : MAP CONTENT IS NULL");
} else {
// 获取脚本引擎
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("javascript");
// 绑定数据
ScriptContext newContext = new SimpleScriptContext();
Bindings bind = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
bind.putAll(map);
try {
engine.setBindings(bind, ScriptContext.ENGINE_SCOPE);
engine.eval(js);
} catch (Exception e) {
log.info("EXECJS EXCEPTION : EXECUTE JAVASCRIPT EXCEPTION", e);
throw (e);
}// end try
}// end if
}
}
‘玖’ 求实训内容 JAVA程序
public class Test
{
public static void main(String[] args)
{
Rctangle r=new Rctangle(3, 4);
Circle c=new Circle(2);
Square s=new Square(3);
System.out.println(r);
System.out.println(c);
System.out.println(s);
}
}
interface Shape
{
double length();
double area();
}
class Rctangle implements Shape
{
double x, y;
Rctangle(double x, double y)
{
this.x=x;
this.y=y;
}
public double length()
{
return (x+y)*2;
}
public double area()
{
return x*y;
}
public String toString()
{
return "面积:"+area()+" 周长:"+length();
}
}
class Circle implements Shape
{
double r;
Circle(double r)
{
this.r=r;
}
public double length()
{
return 2*Math.PI*r;
}
public double area()
{
return Math.PI*r*r;
}
public String toString()
{
return "面积:"+area()+" 周长:"+length();
}
}
class Square implements Shape
{
double x, y;
Square(double x)
{
this.x=x;
this.y=x;
}
public double length()
{
return (x+y)*2;
}
public double area()
{
return x*y;
}
public String toString()
{
return "面积:"+area()+" 周长:"+length();
}
}
‘拾’ java 请问编写自动脚本
packageeg;
importjava.util.Random;
publicclassRandomNumber{
publicstaticvoidmain(String[]args){
RandomNumberrn=newRandomNumber();
Rulerule=newRule(){
@Override
protectedbooleanisAvailable(Integernumber){
if(number%17!=0&&!number.toString().startsWith("2")&&!number.toString().endsWith("7")){
returntrue;
}
returnfalse;
}
};
StringBufferbuffer=newStringBuffer();
for(inti=0;i<1000000;i++){
Integernum=rn.getRandomNumber(1,500,rule);
if(buffer.length()==0){
buffer.append(num);
}else{
buffer.append(","+num);
}
}
System.out.println(buffer.toString());
}
publicIntegergetRandomNumber(Integermin,Integermax,Rulerule){
Randomrdm=newRandom();
Integernumber=rdm.nextInt(max)+min;
if(rule.isAvailable(number)){
returnnumber;
}else{
returngetRandomNumber(min,max,rule);
}
}
}
abstractclassRule{
(Integernumber);
}