我用FileUpload上传文件,在Tomcat中可以使用,可是到了weblogic就不能用了
org.apache.commons.fileupload.DiskFileUpload fu = new org.apache.commons.fileupload.DiskFileUpload();
// 设置允许用户上传文件大小,单位:字节
fu.setSizeMax(10000000);
// maximum size that will be stored in memory?
// 设置最多只允许在内存中存储的数据,单位:字节
fu.setSizeThreshold(4096);
// 设置一旦文件大小超过getSizeThreshold()的值时数据存放在硬盘的目录
fu.setRepositoryPath(prefix);
//开始读取上传信息
List fileItems = fu.parseRequest(request);
Iterator iter = fileItems.iterator();
while (iter.hasNext()) {
org.apache.commons.fileupload.FileItem item = (org.apache.commons.fileupload.FileItem) iter.next();
//忽略其他不是文件域的所有表单信息
if (!item.isFormField()) {
String name = item.getName();
long size = item.getSize();
if(size> 1000000)
{
out.println( "上传文件大小不能超过1M ");
out.println( " <a href= 'importsn.jsp '> 返回 </a> ");
return ;
}
if((name==null||name.equals( " ")) && size==0)
continue;
//保存上传的文件到指定的目录
name = name.replace( ': ', '_ ');
name = name.replace( '\\ ', '_ ');
//prefix=prefix + "\\ " + name;
prefix=prefix + "\\ " + name;
java.io.File f1=new java.io.File( prefix);
item.write(f1);
在weblogic运行提示the request was rejected because no multipart boundary was found 怎么解决呀。
------解决方案--------------------另外你所用的DiskFileUpload已经是一个过时的类了,现在FileUpload提倡用ServletFileUpload和DiskFileItemFactory类联合使用来替代DiskFileUpload类,具体使用如下:
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(10240);
factory.setRepository(new java.io.File( "d://Apache Group "));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(10240);
java.util.List/* FileItem */items = upload.parseRequest(request);
java.util.Iterator iter = items.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
}