上网下载吧!网上有已经写好的Bean,好像叫SmartUpload—————————————————————————————————
┏━★━━◆━━★━┓ 
♂欢|◢CSDN◣|使♂        ▲自由保存帖子,浏览,关注检测
┃迎|◥论坛助手◤|用┃        ▲完善的CSDN客户端工具
┗━☆━━◇━━━☆┛       ▲自动添加签名......让你更快,更爽,更方便地上CSDN...
http://www.csdn.net/expert/topic/573/573604.xml
http://www.chinaok.net/csdn/csdn.zip

解决方案 »

  1.   


    <%@ page language="java" import="com.jspsmart.upload.*"%>
    <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML>
    <BODY BGCOLOR="white">
    <H1>jspSmartUpload : Sample 1</H1>
    <HR><% // Variables
    int count=0;         // Initialization
    mySmartUpload.initialize(pageContext); mySmartUpload.setTotalMaxFileSize(100000); // Upload
    mySmartUpload.upload(); try { // Save the files with their original names in the virtual path "/upload"
    // if it doesn't exist try to save in the physical path "/upload"
    count = mySmartUpload.save("/upload");

    // Save the files with their original names in the virtual path "/upload"
    // count = mySmartUpload.save("/upload", mySmartUpload.SAVE_VIRTUAL); // Display the number of files uploaded 
    out.println(count + " file(s) uploaded."); } catch (Exception e) { 
    out.println(e.toString());
    }

    %></BODY>
    </HTML>
      

  2.   

    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.lang.*" %>
    <%@ page import="com.jspsmart.upload.*" %>
    <%
        //实例化上载bean
        com.jspsmart.upload.SmartUpload mySmartUpload=new com.jspsmart.upload.SmartUpload();
        //初始化
        mySmartUpload.initialize(pageContext);
        //设置上载的最大值
        mySmartUpload.setMaxFileSize(500 * 1024*1024);
        //上载文件
        mySmartUpload.upload();
       //循环取得所有上载的文件
       for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
       //取得上载的文件
       com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
       if (!myFile.isMissing())
        {
       //取得上载的文件的文件名
        String myFileName=myFile.getFileName();
        //取得不带后缀的文件名
        String  suffix=myFileName.substring(0,myFileName.lastIndexOf('.'));
        //取得后缀名
        String  ext= mySmartUpload.getFiles().getFile(0).getFileExt();  
        //取得文件的大小  
        int fileSize=myFile.getSize();
        //保存路径
        String aa=getServletContext().getRealPath("/")+"jsp\\";
        String trace=aa+myFileName;
        //取得别的参数
        String explain=(String)mySmartUpload.getRequest().getParameter("text");
        String send=(String)mySmartUpload.getRequest().getParameter("send");
        //将文件保存在服务器端 
        myFile.saveAs(trace,mySmartUpload.SAVE_PHYSICAL);
    out.println(("上载成功!!!").toString());
       }
       else 
       { out.println(("上载失败!!!").toString()); } 
       }//与前面的if对应
    %>
      

  3.   

    http://www.jspsmart.com
    这里又jspsmartupload的下载,另外还有很多其他的东东。