[問題] applet使用listfile的問題
目標:
網頁呼叫applet裡的class,填入的值為查詢路徑(C:/),
applet功能是列出所有路徑內的檔案,並印出檔名。
問題:
網頁有傳送值給applet,
並且用print印出程式跑到哪,
在File[] files = filedir.listFiles();時
就不會再往下跑,
在pro()內有印出取得的路徑,
但程式跑完不會有error訊息,
但是會自動不跑。
-------test.class----------
import java.applet.Applet;
import java.io.File;
import java.io.IOException;
public class test extends Applet{
private String meg = "";
//設定網頁傳來的參數
public void setMeg(String str){
meg = str;
}
public void pro(){
String text = "";
//印出傳送來的路徑
System.out.println("Parameter : "+meg);
//宣告接受的路徑
File filedir = new File(meg);
//取出所有檔案 ps:此處無法執行!! 程式跑到此行時就會結束
File[] files = filedir.listFiles();
for(int i=0 ; i<files.length ; i++){
File fileList = files[i];
//印出檔案名稱
System.out.println(fileList.getName());
}
}
}
------------test.html--------------------
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html">
<title>新增網頁1</title>
</head>
<script>
function a(){
<!--設定參數 -->
var form = document.form1;
var id = form.name.value;
<!-- 設定apple名稱-->
var app = document.getElementById('test');
<!-- 設定路徑 ex: C:/Windows-->
app.setMeg(id);
app.pro();
}
</script>
<body >
<p align="center">
<!-- 設定applet -->
<applet
code=test.class
name=test
archive="Demo.jar"
width=0
height=0>
</applet>
</body>
</html></p>
</applet>
<form method="POST" name="form1">
<p> </p>
<!-- 設定路徑 ex: C:/Windows-->
<p>id:<input type="text" name="name" size="20"></p>
<p>
<!-- 按button後呼叫a() -->
<input type="button" value="ok" onclick=a();></p>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 124.219.29.125
推
11/01 15:35, , 1F
11/01 15:35, 1F
→
11/01 15:37, , 2F
11/01 15:37, 2F
推
11/01 16:47, , 3F
11/01 16:47, 3F
※ 編輯: BossPi 來自: 124.219.29.125 (11/01 17:18)
※ 編輯: BossPi 來自: 124.219.29.125 (11/02 09:21)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):