, 2.

@ResponseBody @RequestMapping("/photo", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); return IOUtils.toByteArray(in); }


, 3.

@RequestMapping("/photo") public void photo(HttpServletResponse response) throws IOException { response.setContentType("image/jpeg"); InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); IOUtils.copy(in, response.getOutputStream()); }


, 4.

@ResponseBody @RequestMapping("/photo2) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); return IOUtils.toByteArray(in); }


">
MCQs > IT & Programming > Spring MVC >

Which of the following code samples will correctly return an image in @ResponseBody from a byte[] of image data?

Spring MVC MCQs

Which of the following code samples will correctly return an image in @ResponseBody from a byte[] of image data?

Answer

Correct Answer:

@ResponseBody @RequestMapping("/photo", method = RequestMethod.GET, produces = MediaType.IMAGE_JPEG_VALUE) public byte[] testphoto() throws IOException { InputStream in = servletContext.getResourceAsStream("/images/no_image.jpg"); return IOUtils.toByteArray(in); }


Explanation:

Note: This Question is unanswered, help us to find answer for this one

Spring MVC Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

Spring MVC Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it