title: How do I determine whether an image saved in a database is .gif, .jpg or .png to display on a servlet
body: <p>I want to retrieve images from a database (MySQL, saved as a LongBlob field). They can be .gif, .jpg or .png images. Returning them to the client from the servlet requires using something like, to set the content type:</p>
  
  <pre><code>response.setContentType("image/gif");
  </code></pre>
  
  <p>But this only works properly in all browsers if the image is a gif. Can I identify if the image is a gif or jpg by reading the bytes or can I specify a generic ContentType that handles all images. </p>