Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt from jdiscuss

 
dolly shah
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Collins Mbianda
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    Marc Peabody
    pie sneak
    Sheriff
    Posts: 4727
    Mac Ruby VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The input element is a file type which allows the user to upload a file.
     
    dolly shah
    Ranch Hand
    Posts: 383
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks to both of you. I got it now.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic