相对于<input type="file"/>
我想做个备份. 在网页上选择保存路径,点击“备份”按钮可以把数据库备份到指定位置
就是不知道怎么能上传那个路径?那个选择保存路径的对话框怎么弄出来?

解决方案 »

  1.   

    String filePath = "路径文件名";
    resp.reset();
    if (filePath.endsWith(".doc") || filePath.endsWith(".rtf")) {
    resp.setContentType("application/msword");
    resp.setHeader("Content-disposition", "inline; filename="
    + URLEncoder.encode(fileName, "UTF-8"));
    } else if (filePath.endsWith(".pdf")) {
    resp.setContentType("application/pdf");
    resp.setHeader("Content-disposition", "inline; filename="
    + URLEncoder.encode(fileName, "UTF-8"));
    } else if (filePath.endsWith(".xls")) {
    resp.setContentType("application/vnd.ms-excel");
    resp.setHeader("Content-disposition", "inline; filename="
    + URLEncoder.encode(fileName, "UTF-8"));
    } else {
    resp.setContentType("application/x-msdownload");
    resp.setHeader("Content-disposition",
    "attachment; filename="
    + URLEncoder.encode(fileName, "UTF-8"));
    }
    File file = new File(filePath);
    // 如果是相对路径
        if(!file.exists()) 
         file = new File(req.getSession().getServletContext().getRealPath("/"+ filePath));
    FileInputStream in = org.apache.commons.io.FileUtils
    .openInputStream(file);
    ServletOutputStream sout = resp.getOutputStream();
    int filesize = org.apache.commons.io.IOUtils.copy(in, sout);
    sout.close();