File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt from jdiscuss" Watch "doubt from jdiscuss" New topic

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?




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

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

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





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

    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:
    subject: doubt from jdiscuss
    It's not a secret anymore!