[color=red]本地上传时读取本地文件的路径[/color]<form name= "form1 " enctype= "multipart/form-data " method= "post" action= "">
<input type= "file" name="file">
<input type= "submit" name= "Submit " value= "上传 ">
</form>
[color=red]下载到本地时设置本地文件夹的目录路径[/color]
首先在JS里添加函数
<script language="JavaScript" type="text/JavaScript">
function browseFolder(path) {
try {
var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
var Shell = new ActiveXObject("Shell.Application");
var Folder = Shell.BrowseForFolder(0, Message, 64, 17);//起始目录为:我的电脑
//var Folder = Shell.BrowseForFolder(0,Message,0); //起始目录为:桌面
if (Folder != null) {
Folder = Folder.items(); // 返回 FolderItems 对象
Folder = Folder.item(); // 返回 Folderitem 对象
Folder = Folder.Path; // 返回路径
if (Folder.charAt(Folder.length - 1) != "\\") {
Folder = Folder + "\\";
}
document.getElementById(path).value = Folder;
return Folder;
}
}
catch (e) {
alert(e.message);
}
}
</script>
然后在JSP里
<td>
<input type="text" name="path" />
</td>
<td>
<input type="button" οnclick="browseFolder('path')"
value="选择生成路径" />
</td>
<input type= "file" name="file">
<input type= "submit" name= "Submit " value= "上传 ">
</form>
[color=red]下载到本地时设置本地文件夹的目录路径[/color]
首先在JS里添加函数
<script language="JavaScript" type="text/JavaScript">
function browseFolder(path) {
try {
var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息
var Shell = new ActiveXObject("Shell.Application");
var Folder = Shell.BrowseForFolder(0, Message, 64, 17);//起始目录为:我的电脑
//var Folder = Shell.BrowseForFolder(0,Message,0); //起始目录为:桌面
if (Folder != null) {
Folder = Folder.items(); // 返回 FolderItems 对象
Folder = Folder.item(); // 返回 Folderitem 对象
Folder = Folder.Path; // 返回路径
if (Folder.charAt(Folder.length - 1) != "\\") {
Folder = Folder + "\\";
}
document.getElementById(path).value = Folder;
return Folder;
}
}
catch (e) {
alert(e.message);
}
}
</script>
然后在JSP里
<td>
<input type="text" name="path" />
</td>
<td>
<input type="button" οnclick="browseFolder('path')"
value="选择生成路径" />
</td>