如何使用java在动态路径中上传文件

时间:2017-03-02 06:37:12

标签: javascript java jsp

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或servlets上传文件。 每当我上传文件时,它都应该通过弹出窗口动态询问路径,询问存储位置。

1 个答案:

答案 0 :(得分:0)

以下是一些参考资料:

$('#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()
    }
})
相关问题