upload = FileUpload.fileUpload(file, file_save_name, prefix,"manyPicture");if (!upload) {
request.setAttribute("_JavaScript",
"alert('上传图片失败!请检查后重新尝试');window.history.back();");
return mapping.findForward("info");
} 调用的上传类中的部分代码: Context ic = new InitialContext();
ic = (Context) ic.lookup("java:comp/env/");
szPath = (String) ic.lookup(filePath); fileName = file.getFileName();
if (fileName != null && !fileName.equals(""))
{
fullPath = prefix + szPath + SEPERATOR + fileSaveName; File newFile = new File(fullPath);
if (!newFile.exists())
{
newFile.createNewFile();
} bis = new BufferedInputStream(file.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(newFile));
byte[] buffer = new byte[1024];
int bytesRead = 0;
long hastransfered = 0;
long size = 10000*1024; //10000单位是Kb
while ((bytesRead = bis.read(buffer, 0, 1024)) != -1)
{
bos.write(buffer, 0, bytesRead);
hastransfered+=bytesRead;
if(hastransfered>=size)
{
return false;
}
} bis.close();
bos.close();
file.destroy();
request.setAttribute("_JavaScript",
"alert('上传图片失败!请检查后重新尝试');window.history.back();");
return mapping.findForward("info");
} 调用的上传类中的部分代码: Context ic = new InitialContext();
ic = (Context) ic.lookup("java:comp/env/");
szPath = (String) ic.lookup(filePath); fileName = file.getFileName();
if (fileName != null && !fileName.equals(""))
{
fullPath = prefix + szPath + SEPERATOR + fileSaveName; File newFile = new File(fullPath);
if (!newFile.exists())
{
newFile.createNewFile();
} bis = new BufferedInputStream(file.getInputStream());
bos = new BufferedOutputStream(new FileOutputStream(newFile));
byte[] buffer = new byte[1024];
int bytesRead = 0;
long hastransfered = 0;
long size = 10000*1024; //10000单位是Kb
while ((bytesRead = bis.read(buffer, 0, 1024)) != -1)
{
bos.write(buffer, 0, bytesRead);
hastransfered+=bytesRead;
if(hastransfered>=size)
{
return false;
}
} bis.close();
bos.close();
file.destroy();
其它的上传组件就自己写一下判断,应该不难