uploadfile组件是apache开发的用于文件上传的JAVA组件。笔者经过研究,终于实现了动态多文件向数据库上传,现将示例程序介绍如下:
1.组件:笔者使用的是commons-upload-1.2.jar和commons-io-1.3.2.jar,下载后将这两个jar包复制到WEBROOT/WEB-INF/lib下。
2.JSP文件:
var attachname = "attach";
var i=1;
function addInput(){
if(i>0){
var attach = attachname + i ;
if(createInput(attach))
i=i+1;
}
}
function deleteInput(){
window.alert(i);
if(i>1){
i=i-1;
if(!removeInput())
i=i+1;
}
}
function createInput(nm){
var aElement=document.createElement("input");
aElement.name=nm;
aElement.id=nm;
aElement.type="file";
aElement.size="50";
var obj = document.getElementById("upload");
var r =obj.insertRow().insertCell();
temp = " ";
r.innerHTML+=temp;
return true;
//aElement.value="thanks";
//aElement.οnclick=Function("asdf()");
// if(document.getElementById("upload").appendChild(a Element) == null)
// return false;
// return true;
}
function removeInput(){
var obj = document.getElementById("upload");
//if(obj.rows.length == 1) return false;
obj.deleteRow();
return true;
//if(aElement.removeChild(aElement.lastChild) == null)
// return false;
//return true;
}
">
My JSP 'MyJsp.jsp' starting page
-->
1.组件:笔者使用的是commons-upload-1.2.jar和commons-io-1.3.2.jar,下载后将这两个jar包复制到WEBROOT/WEB-INF/lib下。
2.JSP文件:
var attachname = "attach";
var i=1;
function addInput(){
if(i>0){
var attach = attachname + i ;
if(createInput(attach))
i=i+1;
}
}
function deleteInput(){
window.alert(i);
if(i>1){
i=i-1;
if(!removeInput())
i=i+1;
}
}
function createInput(nm){
var aElement=document.createElement("input");
aElement.name=nm;
aElement.id=nm;
aElement.type="file";
aElement.size="50";
var obj = document.getElementById("upload");
var r =obj.insertRow().insertCell();
temp = " ";
r.innerHTML+=temp;
return true;
//aElement.value="thanks";
//aElement.οnclick=Function("asdf()");
// if(document.getElementById("upload").appendChild(a Element) == null)
// return false;
// return true;
}
function removeInput(){
var obj = document.getElementById("upload");
//if(obj.rows.length == 1) return false;
obj.deleteRow();
return true;
//if(aElement.removeChild(aElement.lastChild) == null)
// return false;
//return true;
}
">
My JSP 'MyJsp.jsp' starting page
-->