0
好吧,所以我創建了一個音樂上傳網站,上傳OGG音樂。它還包含一個音頻標記器。我還將專輯封面作爲字符串放入我的數據庫中。嗨,我需要幫助在我的JSP頁面流圖像
現在,我要顯示該字符串(代表我的專輯封面),以我的JSP:
@WebServlet(name = "LoadAlbumArt", urlPatterns = { "/LoadAlbumArt" })
public class LoadAlbumArt extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> 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) {
// ...
}
// ...
}
}
此外,這是Java servlet頁面:
src=<%="\"LoadAlbumArt?musicno="+request.getParameter("musicno") +"\""%>>
而你的問題是? – 2012-03-02 03:00:37
@CengizCan對不起,我的問題是爲什麼它沒有出現在我的網站上? – 2012-03-03 04:08:07
你說什麼「它沒有出現在我的網站上」是什麼意思? 任何錯誤消息/代碼? 你使用什麼容器或應用程序服務器? 什麼瀏覽器? – t0r0X 2012-04-05 08:31:42