2017-03-02 50 views
0
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的要上傳的文件中動態路徑的文件。 每當我上傳一個文件時,它應該通過一個彈出窗口動態詢問路徑,詢問存儲的位置。如何使用Java

回答

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() 
    } 
}) 
:使用JSP和servlet https://www.javacodegeeks.com/2013/08/file-upload-example-in-servlet-and-jsp.html
  • 彈出輸入提交前和追加投入,形成(使用jquery &引導)https://jsfiddle.net/u3sr6smr/

    • 上傳文件