Note that there are some explanatory texts on larger screens.

plurals
  1. POHi I need help in streaming image in my JSP page
    text
    copied!<p>Okay, so I have created a music uploading website that uploads OGG music. It also has an audio tagger incorporated. I also put the album art into my database as a string.</p> <p>Now, I want to display that string (representing my album art) to my JSP:</p> <pre><code>@WebServlet(name = "LoadAlbumArt", urlPatterns = { "/LoadAlbumArt" }) public class LoadAlbumArt extends HttpServlet { /** * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt; methods. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("image/jpg"); try { OutputStream outputStream = response.getOutputStream(); DBConnector bConnector = new DBConnector(); PreparedStatement preparedStatement = bConnector .Connect("SELECT * FROM devwebmp3.musicdatabase where musicno = ?"); preparedStatement.setInt(1, Integer.parseInt(request.getParameter("musicno"))); ResultSet resultSet = preparedStatement.executeQuery(); Blob blob = null; String imagestring = null; while (resultSet.next()) { imagestring = resultSet.getString("albumart"); } //BufferedImage bi = ImageIO.read(ImageIO.createImageInputStream(new ByteArrayInputStream(Base64Coder.decode(imagestring.toCharArray())))); //outputStream.write(blob.getBytes(1, (int) blob.length())); byte[] hello = Base64Coder.decode(imagestring); //ImageIO.write(bi, "jpg", outputStream); //System.out.println("byte" + hello); outputStream.write(hello); outputStream.flush(); outputStream.close(); } catch (Exception e) { // ... } // ... } } </code></pre> <p>In addition, this is the java servlet page:</p> <pre><code>src=&lt;%="\"LoadAlbumArt?musicno="+request.getParameter("musicno") +"\""%&gt;&gt; </code></pre>
 

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