Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplay an image from a blob field using servlet
    primarykey
    data
    text
    <p>i created a jsp page that calls another jsp page that show an image took from a blob field in my mysql db:</p> <pre><code>&lt;img src="blob.jsp"&gt; </code></pre> <p>it works. But, somewhere in this forum i read that this is not the right way to do it. I should, instead, using a servlet this way:</p> <pre><code> &lt;img src="servlet_name"&gt; </code></pre> <p>I created a servlet, but it doesent show me the image it shows me this</p> <pre><code>ÿØÿàJFIFHHÿí$Photoshop 3.08BIMí ResolutionHH8BIM FX Global Lighting Anglex8BIMFX Global Altitude8BIMó Print Flags 8BIM Copyright Flag8BIM'Japanese Print Flags 8BIMõColor Halftone SettingsH/fflff/ff¡™š2Z5-8BIMøColor Transfer Settingspÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿè8BIM Layer State8BIM Layer Groups8BIMGuides@@8BIM URL overrides8BIMSlicesuƒD Untitled-1Dƒ8BIMICC Untagged Flag </code></pre> <p>This is my simple servlet</p> <pre><code>package Jeans; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.sql.Blob; import java.sql.ResultSet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/BlobDisplay") public class BlobDisplay extends HttpServlet { private static final long serialVersionUID = 1L; GestioneDB gestioneDB ; public BlobDisplay() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Blob image = null; byte[ ] imgData = null ; String query = null; query = request.getParameter(query); gestioneDB = new GestioneDB(); ResultSet rs = gestioneDB.rs("select immagine_principale from news where id ='217'"); try{ if (rs.next()) { image = rs.getBlob("immagine_principale"); imgData = image.getBytes(1,(int)image.length()); response.setContentType("image/jpg"); OutputStream o = response.getOutputStream(); o.write(imgData); o.flush(); o.close(); } } catch(Exception e){} } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request,response); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload