jsp+sql2000,想做上传下载。
之前用jspsmartupload做过上传,由于不知道jspsmartupload怎么连接数据库,下载就不会做。我想只要客户端上传一个文件,就可以马上下载的那种。
   应该要连接到数据库吧,记录路径。,
   
不知道怎么做?

解决方案 »

  1.   

    http://stephen830.iteye.com/blog/255583
      

  2.   

    如要定稿到数据库,要在PhotoMgr.java里修改,DBC为调用数据库连接池,百度一下很多:         for (k=0; k<su.getFiles().getCount();k++) {
                suFile = su.getFiles().getFile(k);
                suFile.saveAs(filePath+fileName,SmartUpload.SAVE_PHYSICAL);             //获取上传文件ID序列
    fid=""+DBC.GetNextID("user_upload_file");
    sql="insert into user_upload_file"+
    "(id, oldflnm, newflnm, fsize, uptim) "+
    "values('"+fid+"', '"+oldFlnm+"', '"+newFullFlnmPath+"', '"+fileSize+"', '20"+comuse.GetDateTime()+"')";
    //执行写入到数据库
    DBC.executeUpdate(sql);
    //System.out.println(sql);
            }文件下载页面:<%@page language="java" contentType="application/x-msdownload" pageEncoding="gb2312" import="java.sql.*,java.io.*"%><%
    String id=request.getParameter("id");
    String tab=request.getParameter("tab");
    String fdir=request.getParameter("fdir");
    String oldflnm=request.getParameter("oldflnm");
    String newflnm=request.getParameter("newflnm");
    if(id==null || tab==null || oldflnm==null || newflnm==null) response.sendRedirect("/Error.htm");
    else{
    boolean notdownload=true;
    DBConn.DB DBC=null;
    ResultSet rs=null;
    String old_flnm="", sav_flnm="", filedownload="", filedisplay="";
    try{
    DBC=new DBConn.DB(session);
    rs=DBC.executeQuery("select * from "+tab+" where id="+id);
    if(rs.next()) {
    old_flnm=rs.getString(oldflnm);
    sav_flnm=rs.getString(newflnm); filedownload=request.getRealPath(fdir+sav_flnm); //要提供下载的文件的物理路径+文件名
    filedisplay = old_flnm; //给用户提供的下载文件名
    filedisplay = new String(filedisplay.getBytes("gb2312"),"iso-8859-1"); java.io.File fl=new java.io.File(filedownload);
    if(fl.exists()) { //判断文件是否存在
    notdownload=false;
    response.reset(); //可加也可不加
    response.setContentType("application/x-msdownload"); //让浏览器知道文件类型(x-download)
    response.addHeader("Content-Disposition","attachment;filename=" + (filedisplay));
    OutputStream outp = null;
    FileInputStream in = null;
    try{
    outp = response.getOutputStream();
    in = new FileInputStream(filedownload);

    byte[] b = new byte[1024];
    int i = 0;

    while((i = in.read(b)) > 0){
    outp.write(b, 0, i);
    }
    outp.flush();
    notdownload=false;
    }
    catch(Exception e){
    System.out.println("Error!");
    e.printStackTrace();
    }
    finally{
    if(in != null){
    in.close();
    in = null;
    }
    if(outp != null){
    outp.close();
    outp = null;
    }
    }
    } //end fl.exists()
    if(notdownload) {
    out.println("<script language='javascript'>\nalert('Sorry,无法下载此文件。\\n\\n可能是服务器无响应,或文件已被删除。'); window.close();\n</script>");
    }
    } //end rs.next()
    } catch(Exception e) { out.println("//"+e.toString()); }
    finally {
    try { if(rs!=null) rs.close(); } catch(Exception e) {}
    try { DBC.destroy(); } catch(Exception e) {}
    }
    }
    %>