The following HTML snippet makes a POST request to a servlet SendFileName
.
<form method="post" action="SendTheFileName" enctype="multipart/form-data">
<div id="Files_to_be_shared">
<input type="file" id="File" name="FileTag" />
<input type="submit" value="Share" />
</div>
</form>
In the servlet's POST method I try to get the file name by calling :
String FileName = request.getParameter("FileTag")
but I am getting null
. Why is that ?
I am using Apache commons for file upload. It is working fine. I don't know why do I get null when the enctype is multipart/form-data while using only the jdk.
Servlet 3.0 API (Java EE 6) provides methods to access the content of a multipart post:
See HttpServletRequest.getParts()
You should have one Part
for the file and one for each parameter.