选择文件页面:
<script type="text/javascript">
function startclick(){
if(document.getElementById("startdate").value==""){
alert("请输入开始时间");
return;
}
if(document.getElementById("stopdate").value==""){
alert("请输入终止时间");
return;
}
if(document.getElementById("file").value==""){
alert("请选择文件");
return;
}
document.getElementById("form").submit();
}
</script>
<body>
<form id="form" action="excel.jsp" method="post" enctype="multipart/form-data">
开始时间:<input type="date" name="startdate" id="startdate"/>终止时间<input name="stopdate" type="date" id="stopdate"/>
选择文件:<input type="file" id="file" name="file"/>
<input type="button" value="确定" onclick="javascript:startclick()"/>
</form>
文件处理页面:
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.SmartUpload();
//上传初始化
try{
mySmartUpload.initialize(pageContext);
mySmartUpload.setMaxFileSize(10*1024*1024);
//设置所有文件最大容量
mySmartUpload.setTotalMaxFileSize(100*1024*1024);
mySmartUpload.setAllowedFilesList("xls");
//上传
mySmartUpload.upload();//获取文件
com.jspsmart.upload.Files myfile = mySmartUpload.getFiles();
System.out.println(myfile.getCount());
com.jspsmart.upload.File file=myfile.getFile(0);//在这里出错,上面打印文件个数为0.
// file.saveAs("D://aaa.xls");
}catch(Exception e){
e.printStackTrace();
}