permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt from jdiscuss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt from jdiscuss" Watch "doubt from jdiscuss" New topic
Author

doubt from jdiscuss

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
How can you retrieve the data sent by the FORM displayed by following HTML page code?

Code

<html>

<body>

<form action="/myapp/SaveServlet" method="POST">

<input type="file" name="name">

<input type="submit" value="POST">

</form>

</body>

</html>


Options

Select 2 correct options.


1 request.getParameter("name");


2 request.getAttribute("name");


3 request.getInputStream();


4 request.getReader();
The answers are 3 & 4. I thought the answer is only 1. Anyone can explain?


SCJP-1.5<br />SCWCD-1.4
Collins Mbianda
Ranch Hand

Joined: Aug 11, 2007
Posts: 259
Hi dolly !!!

A request's parameter is a pair String/String.
request.getParameter("name"); will return you a String

Here name is a File you cannot get it with the method getParameter().

You have two posibilities:
  • Retrieve the body as character data using BufferedReader with the method getReader().

  • (public BufferedReader getReader() throws IOException )

  • Retrieve the body of the request as binary data using ServletInputStream with getInputStream().

  • (public ServletInputStream getInputStream() throws IOException )
    Hope It help.
    [ December 28, 2007: Message edited by: Collins Mbianda ]

    SCJP 5.0 | SCWCD 1.4
    Marc Peabody
    pie sneak
    Sheriff

    Joined: Feb 05, 2003
    Posts: 4727

    The input element is a file type which allows the user to upload a file.


    A good workman is known by his tools.
    dolly shah
    Ranch Hand

    Joined: Jun 18, 2007
    Posts: 383
    Thanks to both of you. I got it now.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: doubt from jdiscuss
     
    Similar Threads
    getParameter
    geting focus on radio button
    mock question
    [AJAX] Getting values of checked checkboxes in form
    list......jsp, javascript