如果可以最好能带点注释..  我在BAIDU 搜了N多基本都一样的.大家最好能提供个完整的.谢谢

解决方案 »

  1.   

    baidu里面找"ntsky上传组件"吧,还不错,拿来就可以用,还带源码
      

  2.   

    也可以用struts的上传,很方便的,可以参考struts带的例子
      

  3.   

    代码如下:<%
    try{
    String temp=(String)session.getId();
    File f1=new File((String)request.getRealPath("photo")+"/",temp);//f1对象指向上传文件的所在路径
    out.println(f1);
    FileOutputStream o=new FileOutputStream(f1);//文件输出流指向上传文件所在路径
    out.println(o);
    InputStream in=request.getInputStream();//得到客户端所提交的数据
    byte b[]=new byte[10000000];
    int n;
    while((n=in.read(b))!=-1){
    o.write(b,0,n);
    }
    o.close();
    in.close();
    //读取临时文件f1,从中获取上传文件的名字和上传文件的内容。
    RandomAccessFile random=new RandomAccessFile(f1,"r");//r代表只读
    int second=1;
    String secondLine=null;
    while(second<=2){
    secondLine=random.readLine();
    second++;
    }
    int position=secondLine.lastIndexOf('\\');
    String fileName=new String((secondLine.substring(position+1,secondLine.length()-1)).getBytes("iso-8859-1"), "GB2312");

    random.seek(0);//重新定位使文件指针指到文件头
    long forthEnPosition=0;
    int forth=1;
    while((n=random.readByte())!=1&&(forth<=4)){//取到第四行回车符号所在位置,这是上传文件的开始位置
    if((n=='\n')){
    forthEnPosition=random.getFilePointer();
    forth++;
    }
    }
    File f2=new File((String)request.getRealPath("photo")+"/",fileName);
    session.setAttribute("Name",fileName);//将文件保存入SESSION
    RandomAccessFile random2=new RandomAccessFile(f2,"rw");
    random.seek(random.length());
    long endPosition=random.getFilePointer();
    long =endPosition;
    int j=1;
    while((>=0)&&(j<=6)){//找到上传文件数据结束的位置,即倒数第六行
    --;
    random.seek();
    n=random.readByte();
    if(n=='\n'){
    endPosition=random.getFilePointer();
    j++;
    }
    }
    random.seek(forthEnPosition);
    long startPoint=random.getFilePointer();
    while(startPoint<endPosition-1){//从上传文件数据开始的位置到数据结算的位置,把数据写入TOMCAT下的PHOTO子目录中,以SESSIONID命名
    n=random.readByte();
    random2.write(n);
    startPoint=random.getFilePointer();
    }
    random2.close();
    random.close();
    f1.delete();

    out.println("<script language='javascript'>alert('上传成功');window.close();opener.form1.Photo.value='../photo/"+fileName+"';</script>");

    }catch(IOException e){
    out.println("文件上传失败");
    }
    %>
      

  4.   

    realminmin()      你的程序不行.一运行就出错.
        http://10000.245.3098.com/upload/   这里是运行的.
      

  5.   

    <%@ page import="java.io.*"%>
    你好像没导入包