开发者

How to get full path using <input id="file" name="file" type="file" size="60" > in jsp [duplicate]

开发者 https://www.devze.com 2023-03-25 08:06 出处:网络
This question already has answers here: Closed 10开发者_C百科 years ago. Possible Duplicate: How to get the file path from HTML input form in Firefox 3
This question already has answers here: Closed 10开发者_C百科 years ago.

Possible Duplicate:

How to get the file path from HTML input form in Firefox 3

 <input id="file" name="file" type="file" size="60" >
 <input type="Submit" value="Generate XML" >

I don't want to upload that file!! I need to pass the browsed file from The JSP file to the servlet.


Copy and the paste these two input fields.

<input type="file" name="upload" id="upload" />
<input type="text" name="fileName" id="fileName" value="" />

Below the fields paste this jquery. NOTE: Not forget to include the jquery file.

$("#upload").change(function () {
  var filename = $(this).val();
  $('#fileName').val(filename);
}).change();


Add a hidden input field and save the file name on that field and remove the file from the file input via Javascript.

for example.

HTML

<input type="hidden" value="" name="hd1" id="hdFile"/>
<input id="file" name="file" type="file" size="60" />
<input type="Submit" value="Generate XML" />

JavaScript

var filePath = document.getElementById('file').value;
document.getElementById('hdFile').value = filePath;
document.getElementById('file').value = '';
0

精彩评论

暂无评论...
验证码 换一张
取 消