Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestParameters

 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. got it.
Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic