<input type="file"> reads only file name not full path
I am using Glassfish Server.I have seen the apache file upload to solve it...but i want to implement it in glassfish server.
image.html
<form action="" method="post" enctype="multipart/form-data">
Select a file:
<input type="file" name="first" id="first" />
<br />
<input type="button" name="button" value="upload" id="button" />
<p id="test"></p>
<img src='Unknown.png' id="profile_img" height="200px" width="150px" />
</form>
test.js
$(document).ready(function() {
var filepath= $("#first");
$('#button').click(function() {
$.ajax({
type: "post",
url: "imageservlet",
data: "user="+filepath.val(),
success: function(msg) {
$("#profile_img").attr('src',msg);
$("#test").html(msg).fadeIn("fast");
}
});
});
});
imageservlet.java
String user=request.getParameter("user");
out.print(user);
the output i开发者_StackOverflows file name not full path.
Browsers handle this differently. Not all browsers will let you access the full path name (which makes perfect sense from a security standpoint).
精彩评论