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.