关于commons-fileupload-1.0上传文件的问题 你可能没有关闭stream吧,把代码贴出来看看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是这样的,我先编写了个上传程序在tomcat的webapps/demo下运行,完全没问题.后来由于项目需要,对服务器的上的iis和tomcat进行了整合,之后在把整个站点文件放在d:\wwwweb目录下.这是其他文件没问题,但是多个上传出错了.我还注意到一点,当上传多张只有几K大的gif文件时候不会有问题,传100多K的jpg文件就不能完成,报的错就是上面我留下的.下面是该文件的源码:<%@ page contentType="text/html; charset=gb2312" language="java"%><%@ page import="java.util.*,java.io.*,org.apache.commons.fileupload.*,java.util.regex.Matcher,java.util.regex.Pattern" %><%@ page session="true" buffer="24kb" autoFlush="true" %><%Date datename=new java.util.Date(); DiskFileUpload fu = new DiskFileUpload(); fu.setSizeMax(10*1024*1024); fu.setSizeThreshold(4096); fu.setRepositoryPath("C:\\printtemp"); List fileItems = fu.parseRequest(request); Iterator iter = fileItems.iterator(); String regExp=".+\\\\(.+)$"; int j=1; int photonum=0; String tempphotoname=""; boolean allow=false;//过滤掉的文件类型 String[] errorType={".exe",".com",".cgi",".asp"}; String[] allowType={".jpg",".gif",".bmp",".JPG","GIF","BMP"}; Pattern p = Pattern.compile(regExp); while (iter.hasNext()) { FileItem item = (FileItem)iter.next(); if (!item.isFormField()) { String name = item.getName(); long size = item.getSize(); if((name==null||name.equals("")) && size==0) continue; Matcher m = p.matcher(name); boolean result = m.find(); if (result){ for (int temp=0;temp<errorType.length;temp++){ if (m.group(1).endsWith(errorType[temp])){ allow=false; throw new IOException(name+": wrong type"); } } } String photoname=Integer.toString(datename.getYear())+Integer.toString(datename.getMonth())+Integer.toString(datename.getDate())+Integer.toString(datename.getHours())+Integer.toString(datename.getMinutes())+Integer.toString(datename.getSeconds()); Random r = new Random(); String random = String.valueOf(Math.abs(r.nextInt())).substring(0,4); photoname=photoname+random+Integer.toString(j);String day=Integer.toString(datename.getYear()+1900)+Integer.toString(datename.getMonth()+1)+Integer.toString(datename.getDate()); if(allow){ item.write(new File("D:\\print.139sc.com\\userPhotos\\"+day+"\\"+photoname+fileext)); } else { out.print("<script>alert('上传文件类型不正确');history.back(-1);</script>"); out.close(); } } } }%>部分代码省略. Hibernate 查询速度慢得可怕的问题,请高人看看。 hibernate做批量删除时,怎么效率最高 谁能帮我解释下oracle中游标 hibernate3查询中文查询出现的乱马 请教!急!急!急! 有人用过berkeley的内存数据库么? lucene 中文分词问题 QQ的技术 招聘启事(上海地区):程序开发员,系统分析员 欢迎高手指点(ejb,分不够加) Url中的中文传输问题,Jdk 1.3.08 App server Websphere 3.5--在线等 请教:用jdbc连接数据库,报错“Error establishing socket”,是怎么回事啊?
后来由于项目需要,对服务器的上的iis和tomcat进行了整合,之后在把整个站点文件放在d:\wwwweb目录下.这是其他文件没问题,但是多个上传出错了.我还注意到一点,当上传多张只有几K大的gif文件时候不会有问题,传100多K的jpg文件就不能完成,报的错就是上面我留下的.
下面是该文件的源码:<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import="java.util.*,java.io.*,org.apache.commons.fileupload.*,java.util.regex.Matcher,java.util.regex.Pattern" %>
<%@ page session="true" buffer="24kb" autoFlush="true" %>
<%Date datename=new java.util.Date();
DiskFileUpload fu = new DiskFileUpload(); fu.setSizeMax(10*1024*1024); fu.setSizeThreshold(4096);
fu.setRepositoryPath("C:\\printtemp");
List fileItems = fu.parseRequest(request);
Iterator iter = fileItems.iterator();
String regExp=".+\\\\(.+)$";
int j=1;
int photonum=0;
String tempphotoname="";
boolean allow=false;
//过滤掉的文件类型
String[] errorType={".exe",".com",".cgi",".asp"};
String[] allowType={".jpg",".gif",".bmp",".JPG","GIF","BMP"};
Pattern p = Pattern.compile(regExp);
while (iter.hasNext()) {
FileItem item = (FileItem)iter.next();
if (!item.isFormField()) {
String name = item.getName();
long size = item.getSize();
if((name==null||name.equals("")) && size==0)
continue;
Matcher m = p.matcher(name);
boolean result = m.find();
if (result){
for (int temp=0;temp<errorType.length;temp++){
if (m.group(1).endsWith(errorType[temp])){
allow=false;
throw new IOException(name+": wrong type");
}
}
}
String photoname=Integer.toString(datename.getYear())+Integer.toString(datename.getMonth())+Integer.toString(datename.getDate())+Integer.toString(datename.getHours())+Integer.toString(datename.getMinutes())+Integer.toString(datename.getSeconds());
Random r = new Random();
String random = String.valueOf(Math.abs(r.nextInt())).substring(0,4);
photoname=photoname+random+Integer.toString(j);
String day=Integer.toString(datename.getYear()+1900)+Integer.toString(datename.getMonth()+1)+Integer.toString(datename.getDate());
if(allow){
item.write(new File("D:\\print.139sc.com\\userPhotos\\"+day+"\\"+photoname+fileext));
}
else
{
out.print("<script>alert('上传文件类型不正确');history.back(-1);</script>");
out.close();
}
}
}
}
%>部分代码省略.