Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EPractice Lab mock exam 5 question 20

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • 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.
 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed, for binary data the content type should not be "text/*"...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic