簡體   English   中英

如何使用Java在動態路徑中上傳文件

[英]how to upload a file in dynamic paths using java

String rootPath = "C:\\Users\\khaja\\workspace\\ServletFileUploadDownloadExample";
ServletContext ctx = servletContextEvent.getServletContext();
String relativePath = ctx.getInitParameter("tempfile.dir");
File file = new File(rootPath + File.separator + relativePath);
if(!file.exists()) file.mkdirs();
System.out.println("File Directory created to be used for storing files");
ctx.setAttribute("FILES_DIR_FILE", file);
ctx.setAttribute("FILES_DIR", rootPath + File.separator + relativePath);

我想使用Java或JSP或Servlet上傳文件。 每當我上傳文件時,都應通過彈出窗口動態詢問路徑,詢問存儲位置。

以下是一些參考:

$('#submit-btn').click(function(e) {
    e.preventDefault()
    $('#my-modal').modal('show')
})

$('#upload-btn').click(function(e) {
    e.preventDefault()
    var fileLocation = $('#file-location').val(),
        inputExist = $('input[name=fileLocation]', '#upload-form').length > 0
    if (fileLocation && !inputExist) {
        var fileLocationInput = $('<input>').attr('type', 'hidden').attr('name', 'fileLocation').attr('value', fileLocation)
        $('#upload-form').append(fileLocationInput).submit()
    }
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM