谁有实现文件上传得的源代码,用javabean做的,一定给分 自个搜索论坛吧应该有不少关于这方面的问题看看这个例子http://www.csdn.net/expert/topic/651/651822.xml?temp=.2982447 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www-900.ibm.com/developerWorks/java/fileup/index.shtmlhttp://www.code-labs.com/article/articleinfo.php?id=542smartUpload不行吗? import java.io.*;import java.util.*;public class fileLoad { String filepath="c:\\upload"; public fileLoad() { } public void uploadFile(javax.servlet.http.HttpServletRequest req) throws IOException,Exception { try { String contentType=req.getContentType(); int contentLength=req.getContentLength(); java.io.DataInputStream bis=new java.io.DataInputStream(req.getInputStream()); int once = 0; int total = 0; byte[] buffer=new byte[contentLength]; while ((total<contentLength) && (once>=0)) { once = bis.read(buffer,total,contentLength); total += once; } int boundaryStart=contentType.indexOf("boundary="); boundaryStart=boundaryStart+"boundary=".length(); String boundary="--"+contentType.substring(boundaryStart); int pos=getFormNameIndex(buffer,"filename=\"".getBytes(),1)+"filename=\"".length(); int posEnd=getFormNameIndex(buffer,"\"".getBytes(),pos); String filename=new String(buffer,pos,posEnd-pos); pos=filename.lastIndexOf("."); String filenames=System.currentTimeMillis()/1000+filename.substring(pos); pos=getFormNameIndex(buffer,"Content-Type: ".getBytes(),1); pos=getFormNameIndex(buffer,"\r\n".getBytes(),pos+1)+4; int endpos=getFormNameIndex(buffer,boundary.getBytes(),pos+20); int len=endpos-pos; java.io.DataOutputStream bos= new java.io.DataOutputStream(new java.io.FileOutputStream(new java.io.File(filepath,filenames))); bos.write(buffer,pos,len); bis.close(); bos.close(); }catch(Exception exc) { throw new Exception("upload failed."); }finally{ } } private int getFormNameIndex(byte[] source,byte[] formname,int start) { int soulen=source.length; int sealen=formname.length; boolean hasSearch=false; int pos=-1; for(int i=start;i<soulen;i++) { if(source[i]==formname[0]) { boolean hasSear=true; for(int k=1;k<sealen;k++) { if(source[i+k]!=formname[k]) { hasSear=false; break; } } hasSearch=hasSear; } if(hasSearch) { pos=i; break; } } return pos; }} 求一个Flex通过Blaze与spring集成与java后台交互的小例子 如何在struts中实现数据在当前页显示 关于bean的问题 如何更新oracle中的number类型字段? 最近学struts好痛苦 在WEB程序中,如何做到访问IP的限制 在JSP中实现DES加密解密的疑问 帮我看看,怎么编译不通过 菜鸟我来了,大家帮帮菜鸟我,为什么数据不能输出(上一页)跟到(下一页)的啊!多谢了! 文档中根元素前面的标记必须格式正确。问题 大家看看这个效果能不能做? 在JSP中如何实现对于字符串的搜索替换?
import java.util.*;public class fileLoad {
String filepath="c:\\upload";
public fileLoad() {
}
public void uploadFile(javax.servlet.http.HttpServletRequest req) throws IOException,Exception {
try {
String contentType=req.getContentType();
int contentLength=req.getContentLength();
java.io.DataInputStream bis=new java.io.DataInputStream(req.getInputStream());
int once = 0;
int total = 0;
byte[] buffer=new byte[contentLength];
while ((total<contentLength) && (once>=0)) {
once = bis.read(buffer,total,contentLength);
total += once;
}
int boundaryStart=contentType.indexOf("boundary=");
boundaryStart=boundaryStart+"boundary=".length();
String boundary="--"+contentType.substring(boundaryStart);
int pos=getFormNameIndex(buffer,"filename=\"".getBytes(),1)+"filename=\"".length();
int posEnd=getFormNameIndex(buffer,"\"".getBytes(),pos);
String filename=new String(buffer,pos,posEnd-pos);
pos=filename.lastIndexOf(".");
String filenames=System.currentTimeMillis()/1000+filename.substring(pos);
pos=getFormNameIndex(buffer,"Content-Type: ".getBytes(),1);
pos=getFormNameIndex(buffer,"\r\n".getBytes(),pos+1)+4;
int endpos=getFormNameIndex(buffer,boundary.getBytes(),pos+20);
int len=endpos-pos;
java.io.DataOutputStream bos= new java.io.DataOutputStream(new java.io.FileOutputStream(new java.io.File(filepath,filenames)));
bos.write(buffer,pos,len);
bis.close();
bos.close();
}catch(Exception exc) {
throw new Exception("upload failed.");
}finally{ }
}
private int getFormNameIndex(byte[] source,byte[] formname,int start) {
int soulen=source.length;
int sealen=formname.length;
boolean hasSearch=false;
int pos=-1;
for(int i=start;i<soulen;i++) {
if(source[i]==formname[0]) {
boolean hasSear=true;
for(int k=1;k<sealen;k++) {
if(source[i+k]!=formname[k]) {
hasSear=false;
break;
}
}
hasSearch=hasSear;
}
if(hasSearch) {
pos=i;
break;
}
}
return pos;
}
}