SPRING MVC 3 - NOT displaying image in JSP -
i have controller serving images external directory (say c:\images\userid\photo.png), , controller job well. however, img tag in jsp file shows image icon instead of image returned controller.
here's controller:
@requestmapping(value = "/load/{imageid}/", method = requestmethod.get) public responseentity<byte[]> loadimage(@pathvariable("imageid") long imageid, httpservletrequest request) { final org.springframework.http.httpheaders headers = new org.springframework.http.httpheaders(); bufferedimage image; photo photo = photomanager.getsinglephoto(imageid); headers.setcontenttype(mediatype.image_png); seek { if (photo == null) { file defaultfile = new file("c:/images/default.png"); image = imageio.read(defaultfile); homecoming new responseentity<byte[]>(((databufferbyte)image.getdata().getdatabuffer()).getdata(), headers, httpstatus.created); } file file = new file(photo.getpath()); image = imageio.read(file); homecoming new responseentity<byte[]>(((databufferbyte)image.getdata().getdatabuffer()).getdata(), headers, httpstatus.created); } grab (ioexception ex) { homecoming new responseentity<byte[]>(null, headers, httpstatus.not_found); } }
i have found reading other answers here, need include messageconverters in application context, , did it.
here's portion of application-context.xml
<bean class="org.springframework.web.servlet.mvc.annotation.annotationmethodhandleradapter"> <property name="messageconverters"> <util:list> <bean id="bytearraymessageconverter" class="org.springframework.http.converter.bytearrayhttpmessageconverter" /> </util:list> </property> </bean>
the eclipse xml editor complains methodhandleradapter beingness deprecated.
jsp:
<img src="/mavenspringapp/photo/load/131/" width="128" height="128" alt="laf02.jpg">
why isn't image getting displayed when controller sends response correctly (201). in advance.
a little bit of googling tells me http 201 means created
. if image exists, why sending response code telling client created image?
i don't know sure how web browsers handle it, perhaps seek changing response codes 200, aren't creating anything.
spring jsp spring-mvc
No comments:
Post a Comment