title: how to display dynamic images came from dB and showing them in jsp?
body: <p>I need to display images retrieved from DB into my JSP page, help!
  //here is my jsp code line:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;img src="&lt;c:url value="/downloadimage"&gt; 
  &lt;c:param name="id" value="${obj.id}"/&gt;
  &lt;/c:url&gt;" alt="cant show image!" width="200px" height="200px"/&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>//here is my controller method:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@GetMapping("/downloadimage")
  public void  downloadimage(@RequestParam("id") int id,HttpServletRequest request, HttpServletResponse response) {
              
      byte[] imageBytes = autherService.getImageAsBytes(id);
              
      try {
                  
          if(imageBytes != null) {
              response.setContentType(
                       servletContext.getMimeType("name.jpg"));
              response.setContentLength(imageBytes.length);
              response.getOutputStream().write(imageBytes);
          } 
          
      } catch (Exception e) {
          e.printStackTrace();
      }
              
  }</code></pre>
  </div>
  </div>
  </p>
  <p>//here is DAO impl class code :</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>@Override
  public byte[] getImageAsBytes(int id) {
      String sql = "SELECT image FROM picture_tbl WHERE id = ?";
      Object[] args = { id };
      Picture picture = jdbcTemplate.queryForObject(sql,args, new PictureRowMapper());
      return picture.getImageAsBytes();
  }</code></pre>
  </div>
  </div>
  </p>