SPRING MVC 3 - NOT displaying image in JSP -


I have a controller serving images from an external directory (such as c: \ images \ userID \ photo.png) , And this controller does its job very well, however, the IMG tag in my JSP file shows the image icon instead of the image given by this controller.

Here's my controller:

  @RequestMapping (value = "/ load / {imageId} /", method = RequestMethod.GET) public responses & lt; Byte [] & gt; Load Image (@Path Variable ("ImageID") Long image id, HTTPSVette request) {end org.springframework.http.HttpHeaders header = new org.springframework.http.HttpHeaders (); Buffet image image; Photo Photo = Photo Manager. Getsinglephoto (Image ID); Headers.setContentType (MediaType.IMAGE_PNG); Try {if (photo == null) {file defaultFile = new file ("c: /images/default.png"); Image = imageIo Reed (default file); New Response & lt; Byte [] & gt; ((DataBuffered) image .getData (.) GetDataBuffer () back) GetData (), header, httpstats.create); } File file = new file (photo.getPath ()); Image = imageIO.read (file); New Response & lt; Byte [] & gt; ((DataBuffered) image .getData (.) GetDataBuffer () back) GetData (), header, httpstats.create); } Hold (IOException East) {New Reactions & amp; back; [Byte [] & gt; (Blank, headers, http status .NOT_FOUND); }}   

I have to read another answer here, that I need to include message converters in my application context, and I did it.

Here is a part of my application --context.xml

  & lt; Bean class = "org.springframework.web.servlet.mvc.annotation.nnationMethodHandlerAdapter" & gt; & Lt; Property Name = "Message Converters" & gt; & Lt; Util: list & gt; & Lt; Bean id = "byteracem converter" class = "org.springframework.http.converter.biteArrayHttpMessageConverter" /> & Lt; / util: list & gt; & Lt; / Property & gt; & Lt; / Bean & gt;   

Complaining about the Excel XML Editor Math adapter.

JSP:

  & lt; Img src = "/ mavenspringapp / photo / load / 131 /" width = "128" height = "128" alt = "laf02.jpg" & gt;   

The administrator sends the response correctly, even then why the image is not displayed (201). thank you in advanced.

A small googling tells me that http 201 means created . If the image is present, then why are you sending the response code to the customer, who created the picture?

I'm not sure how the web browser handles it, but try to change your response code at 200, because you actually do not create anything.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -