title: How to properly return an image in the response in Spring app?
body: <p>I 'm using Spring 3.0.1.RELEASE for my webapp (and i have no way for upgrading it) and i'm trying to render some images from database on web-page.</p>
  
  <p>I have following simple Spring configs:</p>
  
  <p>spring-application.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:task="http://www.springframework.org/schema/task"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"&gt;
  
      &lt;task:annotation-driven /&gt;
  
      &lt;context:annotation-config /&gt;
  
      &lt;context:spring-configured /&gt;
  
      &lt;context:component-scan base-package="com.me" /&gt;
  
      &lt;bean id="hibernateSessionFactory" class="com.me.dbaccess.HibernateSessionFactory"&gt;
          &lt;constructor-arg ref="sessionFactory"/&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>spring-mvc.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;mvc:annotation-driven/&gt;
  
      &lt;bean id="tilesViewResolver" class="com.me.util.TilesExposingBeansViewResolver"&gt;
          &lt;property name="viewClass" value="com.me.util.TilesExposingBeansView"/&gt;
          &lt;property name="exposeContextBeansAsAttributes" value="true"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="tilesConfigurer"
            class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
          &lt;property name="definitions"&gt;
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/config/tiles-defs.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I have following controller:</p>
  
  <pre><code>@Controller
  public class PhotoController {
      @RequestMapping("/carPhoto.html")
      @ResponseBody
      public byte[] getCarPhoto(
              @RequestParam(UrlParameters.PHOTO_ID) Integer photoId,
              @RequestParam(UrlParameters.PHOTO_TYPE) String photoType) {
          //return image's bytes array from db by photo Id and Type;
      }
  }
  </code></pre>
  
  <p>And finally, I have simple jsp-page:</p>
  
  <pre><code>&lt;%@page contentType="text/html; charset=utf-8"%&gt;
  &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;img id="photoImage" src="&lt;c:url value="/carPhoto.html?photoType=1&amp;photoId=22556793"/&gt;" /&gt;
  </code></pre>
  
  <p>If I open this page  - I can see this image without any problems.</p>
  
  <p>But if I copy image "src" attribute and paste it in browser's address bar (Firefox 19.0.2) - then browser offers me to save carPhoto.html, instead of just render the image. 
  Should I perform some additional setup?</p>