How to get file name for <input type = "file" in jsp
I want to read the file path from html input type="file"
(the entry selected in the file dialog by the user)
<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>
I want the path to the selected file to be read in my Servlet class. How to get the path to the file? Can i read it with var a? Or is there a way to directly access the file path from input type="file"from my servlet?
-, : . , , c:/passwords.txt, , ? java.io.File? ? , . - .
-, : Javascript input type="file" - . , -, c:/passwords.txt onload. , -! ?
, . HTML-, POST multipart/form-data <form>.
<form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit">
</form>
, . API Servlet 2.5 mulipart/form-data, . - Apache Commons FileUpload . , . Servlet 3.0, API , HttpServletRequest#getParts() . .
( http://www.jguru.com/faq/view.jsp?EID=1045507)
A:
- http://www.servlets.com/cos/index.html
- http://www.servlets.com/cos/javadoc/com/oreilly/servlet/MultipartRequest.html - .
B:
- http://commons.apache.org/fileupload/
- invoke readHeaders() org.apache.commons.fileupload.MultipartStream
C:
- http://users.boone.net/wbrameld/multipartformdata/
- invoke getParameter on com.bigfoot.bugar.servlet.http.MultipartFormDatali >