Swati said:
I came across the following question in a mock exam..
How can you retrieve the data sent by the FORM displayed by following HTML page code?
<html>
<body>
<form action="/myapp/SaveServlet" method="POST">
<input type="file" name="name">
<input type="submit" value="POST">
</form>
</body>
</html>
Select 2 correct options.
A.request.getParameter("name");
B.request.getAttribute("name");
C.request.getInputStream();
D.request.getReader();
E.request.getFileInputStream();
ANS: C,D
I think the answer should be A. but the given ans id C,D.
Could someone help me understand how this works ?
Thanks in advance.
See the type, its file. So you are actually uploading a file.
Most importantly you are not setting the enctype to multipart/form-data
so you cannot send the file data. So you can just get the name of the file that user has uploaded by option A.
But if you have enctype="multipart/form-data" in the form tag, then you need to do getInputStream of getReader that is option C,D to get the actually uploaded content.