int count=0;
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
int iSize=mySmartUpload.getSize();
out.println("iSize:"+iSize);
byte lst[]=new byte[iSize];
for(int i=0;i<iSize;i++)
{
lst[i]=mySmartUpload.getBinaryData(i);
}
out.println(lst);
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
int iSize=mySmartUpload.getSize();
out.println("iSize:"+iSize);
byte lst[]=new byte[iSize];
for(int i=0;i<iSize;i++)
{
lst[i]=mySmartUpload.getBinaryData(i);
}
out.println(lst);
计算文件大小?还是报错:This path does not exist (1135).
ServletContext servletContext = getServletContext();
mySmartUpload.getFiles().getFile(0).saveAs( servletContext.getRealPath("upload/") +"/"+ fileName);
更彻底一点的方法可以这样做:
com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
if((myFile.isMissing()))
throw new Exception("Error");
myFile.saveAs("c:\\upload\\temp.txt");
索性指定个物理地址
symbol : variable myUpload
location: class org.apache.jsp.sample1_jsp
com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
^
1 errordjws() 的方法报错。找不到myUpload物理路径试过,不行。
<%@ include file = "header.inc" %><%
Date date = new Date();
String sYear = String.valueOf(date.getYear() + 1900);
String sMonth = String.valueOf(date.getMonth() + 1);
if(sMonth.length()<2) sMonth = "0" + sMonth;
String sPath = sYear + sMonth;String sDestPath = "";
String sAction = request.getParameter("medule");
if(sAction.equals("attachment")){
sDestPath = "G:\\Files\\" + sPath +"\\Attachments\\";
}else{
sDestPath = "G:\\Files\\" + sPath +"\\";
}
File d = new File(sDestPath);
if(!d.exists()) d.mkdir(); // create a new directoryString sFilename = request.getParameter("filepath");
if(sFilename != ""){mySmartUpload.initialize(pageContext);mySmartUpload.upload();
// Select each file
int count = 0;
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
// Save it only if this file exists
if (!myFile.isMissing()) {
// sample with a physical path
File f = new File(sDestPath,myFile.getFileName());
if(f.exists()){
%>
<script>
var msg = "文件已經存在﹗是否要替換﹖";
if((confirm(msg))==false){
window.close();
}
</script>
<%
}
myFile.saveAs(sDestPath + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL); out.println("FileName = " + myFile.getFileName() + "<BR>");
out.println("Size = " + myFile.getSize() + "<BR>");
out.println("FileExt = " + myFile.getFileExt() + "<BR>");
out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
count ++;
// Display the number of files which could be uploaded
out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");
// Display the number of files uploaded
out.println(count + " file(s) uploaded.");
}
}
}
%>
symbol : variable myUpload
location: class org.apache.jsp.sample1_jsp
com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
^
1 errordjws() 的方法报错。找不到myUpload物理路径试过,不行。
我贴的是我写的代码,你用的bean的id是mySmartUpload,将我的myUpload换成mySmartUpload就成了