刚开始传图片的时候没有什么问题,当传个几十张之后图片就不能传上去了,服务器不报任何错误和异常,tomcat的log里面也没有错误信息,只是会在tmp文件夹里面有临时文件存在。访问保存图片这个方法的时候好像也不执行,但是我的系统的其他功能都能正常使用,就只有图片上传这个方法不执行, 如下就是我图片上传这个方法private String saveFile(){
System.out.println(uploadFileFileName); //当不能传图片的时候这一句也不能答打印出来
BufferedOutputStream out = null;
BufferedInputStream in = null;
FileOutputStream fos = null;
FileInputStream fis = null;
try {
if(getFileFileName().indexOf(".")!=-1)
fileFileName = getFileFileName().substring(getFileFileName().lastIndexOf("."));
String str = TimeFormater.formatNowTimetoString("yyyy-MM-dd");
String[] temp = str.split("-");
String tempPath1 =temp[0] + File.separator+temp[1] + File.separator + temp[2]+ File.separator;
String subpath = tempPath1+ Util.createPK()+fileFileName;
String vPath = Systemconfig.basePath+"ptl"+File.separator+webSiteId+File.separator+"upload"+File.separator +subpath;
File folderFile = new File(Systemconfig.basePath+"ptl"+File.separator+webSiteId+File.separator+"upload"+File.separator +tempPath1);
if(!folderFile.exists())
folderFile.mkdirs();
fos = new FileOutputStream(vPath);
fis = new FileInputStream(getFile());
out = new BufferedOutputStream(fos);
in = new BufferedInputStream(fis);
int bytelength = (int)file.length();
byte [] buffer = new byte [255];
while (in.read(buffer) > 0 ) {
out.write(buffer);
}
in.close();
out.close();
fos.close();
fis.close();
subpath = subpath.replaceAll("\\\\", "/");
return subpath;
} catch (Exception e) {
try{
in.close();
out.close();
fos.close();
fis.close();
}catch(Exception ex){
ex.printStackTrace();
}
e.printStackTrace();
return "";
}
}
System.out.println(uploadFileFileName); //当不能传图片的时候这一句也不能答打印出来
BufferedOutputStream out = null;
BufferedInputStream in = null;
FileOutputStream fos = null;
FileInputStream fis = null;
try {
if(getFileFileName().indexOf(".")!=-1)
fileFileName = getFileFileName().substring(getFileFileName().lastIndexOf("."));
String str = TimeFormater.formatNowTimetoString("yyyy-MM-dd");
String[] temp = str.split("-");
String tempPath1 =temp[0] + File.separator+temp[1] + File.separator + temp[2]+ File.separator;
String subpath = tempPath1+ Util.createPK()+fileFileName;
String vPath = Systemconfig.basePath+"ptl"+File.separator+webSiteId+File.separator+"upload"+File.separator +subpath;
File folderFile = new File(Systemconfig.basePath+"ptl"+File.separator+webSiteId+File.separator+"upload"+File.separator +tempPath1);
if(!folderFile.exists())
folderFile.mkdirs();
fos = new FileOutputStream(vPath);
fis = new FileInputStream(getFile());
out = new BufferedOutputStream(fos);
in = new BufferedInputStream(fis);
int bytelength = (int)file.length();
byte [] buffer = new byte [255];
while (in.read(buffer) > 0 ) {
out.write(buffer);
}
in.close();
out.close();
fos.close();
fis.close();
subpath = subpath.replaceAll("\\\\", "/");
return subpath;
} catch (Exception e) {
try{
in.close();
out.close();
fos.close();
fis.close();
}catch(Exception ex){
ex.printStackTrace();
}
e.printStackTrace();
return "";
}
}
解决方案 »
- 关于JSP经常性500问题!
- Hibernate 和Spring 组件
- jsp读取数据库数据生成下拉菜单!
- lucene的索引很容易损坏吗?急切需要帮助!!谢谢!
- 緊急問題求助...jsp网頁異常
- 100分求购JSP电子版教材,讲义,视频讲座.
- 希奇希奇真希奇,麻雀踩死老母鸡!
- jsp、bean和servlet怎么结合?
- 怎么样在JSP得到一个DATE的数据,并把他写到SQLSERVER的datetime字段里面?
- java.sql.Date()和java.util.date()一样吗?他们和SqlServer的date类型是否兼容。。。。
- java sql 语句
- 表单提交参数传递的小问题,求解下
action代码:// ********************************************************
//首先将文件写入一个输入流里面
InputStream is = new FileInputStream(file);
//其次得到你要上传文件到那个目录
String root = ServletActionContext.getRequest().getRealPath("/upload/images");
DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String formatDate = format.format(new Date());
int random = new Random().nextInt(10000);
int position = fileFileName.indexOf(".");
String extension = fileFileName.substring(position) ;
String newFileName = formatDate + random + extension ;
//再次创建一个File来保存你的文件
File destFile = new File(root,newFileName);
//然后就是一个输出流将文件写入到File中。
OutputStream os = new FileOutputStream(destFile);
//以下就是写入文件的方式
byte buffer[] = new byte[2048];
int length = 0;
while((length = is.read(buffer))>0){
os.write(buffer,0,length);
}
//最后一定要关闭流
is.close();
os.close();