當前位置:首頁 » 網頁前端 » java實訓里的腳本
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

java實訓里的腳本

發布時間: 2022-03-09 07:50:43

『壹』 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腳本

  1. java-cp"./classes:./classlib"-Dparam1=zzzzztest.myclass$0

  2. -cp指定classpath

  3. -D指定一個參數,程序內用System.getProperty("param1")訪問

  4. $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);
}