This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getParameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "getParameter" Watch "getParameter" New topic
Author

getParameter

Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
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>


1)request.getParameter("name");

2)request.getAttribute("name");

3)request.getInputStream();

4)request.getReader();

5)request.getFileInputStream();

The correct answer given is 3 and 5. I agree.

But why the answer given 1 is wrong, because there is a parameter name in the html.

This is from Enthuware.

Please advise.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Atul Samnerkar
Ranch Hand

Joined: Sep 20, 2003
Posts: 44


1. In the given example html input "type" is "file" and not "text".
2. getParameter() returns you a String.
3. Being we are tring to access the file request object, we will not get String. Hence this answer is wrong.


Thanks,
Atul Samnerkar
[ August 30, 2008: Message edited by: Atul Samnerkar ]
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Thanks, Atul i had this small doubt
Krzysztof Koziol
Ranch Hand

Joined: Nov 19, 2006
Posts: 133

Originally posted by Amandeep Singh:


5)request.getFileInputStream();

The correct answer given is 3 and 5. I agree.




The getFileInputStream()? Such a method doesn't exist in the HttpServletRequest and in the ServletRequest API. Where did you find it?

Regards,
Krzysztof
[ August 31, 2008: Message edited by: Krzysztof Koziol ]

SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCEA/OCMJEA 5.0
siyabonga khanyile
Greenhorn

Joined: Aug 22, 2008
Posts: 12
The answer should be 3 and 4...we can use both InputStream getInputStream() and BufferedReader getReader()
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
you are right, the answer is 3 and 4.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getParameter
 
Similar Threads
Retrieving Session variables into another JSP
doubt from jdiscuss
include directive and include action
mock question
Problem regarding redirected error message