• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EPractice Lab mock exam 5 question 20

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

EPractice Labs Test Generator Lab delivers test files in the form of encrypted binary format. A developer working on online training lab write a servlet that allows an end user to download test files from the server. Which of the following statements have to be true about this servlet?
A. The file has to be sent using a binary stream acquired using the ServletResponse.getOutputStream() method.
B. The file has to be sent using a binary stream acquired using the ServletResponse.getWriter() method.
C. The ServletRequest.setContentType(string) method has to be used to set the content type.
D. The HttpServletResponse.setHeader("Content-Type", "text/html") method has to be used to set the content type.
E. The file has to be sent using a binary stream acquired using the ServletResponse.getBinaryStream() method.

Given answer: A, D
Since EPractice Labs Test Generator .test files are in binary format, a binary stream has to be obtained using the ServletResponse.getOutputStream() method. Hence A is correct.
The ServletResponse.getWriter method is used to retrieve a text stream that can be used for text data.
If binary contents are written using this stream, the content cannot be encoded properly and hence appears corrupted when it is received at the other end.The content type has to be set so that the web browser handles the file properly.
ServletResponse.setContentType(String contentType)
HttpServletResponse.setHeader("Content-Type", contentType);
D is correct.


I don't think D is correct because the content type of binary is not "text/html". I think the content type should be application/octet-stream.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agreed, for binary data the content type should not be "text/*"...
 
reply
    Bookmark Topic Watch Topic
  • New Topic