小编dee*_*121的帖子

如何在jsp中获取<input type ="file"的文件名

我想从html读取文件路径input type="file" (用户在文件对话框中选择的条目)

<script>   
    function OpenFileDialog(form) {    
        var a = document.getElementById("inputfile").click();
        SampleForm.filePath.value = //set the path here
        document.SampleForm.submit();   
    } 
</script>

<form name="SampleForm" action="TestServlet" method="get">
    <input type="file" style="display:none;" id="inputfile"/> 
    <a href="javascript:OpenFileDialog(this.form);">Open here</a>
    <input type="hidden" name="filePath" value=""/> 
</form>
Run Code Online (Sandbox Code Playgroud)

我希望在我的Servlet类中读取所选文件的路径如何获取文件路径?我能从中读出来var a吗?或者有没有办法input type="file"从我的servlet 直接访问文件路径?

html javascript jsp servlets file-upload

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

file-upload ×1

html ×1

javascript ×1

jsp ×1

servlets ×1