title: How can I display image file object from java to jsp?
body: <p>I have a method which returns a file object of an image:</p>
  
  <pre><code>public File getPhoto(entryId){...}
  </code></pre>
  
  <p>I call this method from my action method and set the file to a DTO File variable:</p>
  
  <pre><code>    myDto.photo = getPhoto(entryId); 
         // where entryId refers to the name of the image file 
         // e.g. ent01 for ent01.gif, ent02 for ent02.gif and so on.
  </code></pre>
  
  <p>Now, in my JSP file I would like to display the image through a code like this:</p>
  
  <pre><code>&lt;img src = "${myDto.photo}"&gt; 
  </code></pre>
  
  <p>However,I realized that the myDto.photo is a file object thus has the absolute path of the file and not the URL needed for the img src in JSP. </p>
  
  <p>Through searching, I understand that I can use a servlet and use something like </p>
  
  <pre><code>&lt;img src = "${pageContext.request.contextPath}/image/ent01.gif"}. 
  </code></pre>
  
  <p>However, I'm a little confused about this one as I wanted the filename part (ent01.gif) to vary based from the input entryId. </p>
  
  <p>I hope anyone can shed light for me on this one. A lot of thanks. </p>