我正在用 jquerymobile + jsp 制作一个应用程序
该结构不像普通的 servlet-jsp MVC。
它直接获取数据并像这样打印,
<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%! Connection con=null; %>
<%! Statement st= null; %>
<%
try {
ResultSet rs= null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/first_app";
String user = "root";
String password = "test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url, user, password);
try {
String sql = "SELECT * FROM lunch_menu";
PreparedStatement ps = con.prepareStatement(sql);
rs = ps.executeQuery();
%>
<div data-role="page">
<div data-role="header">
<h1>MENU PAGE</h1>
<a href="#" data-rel="back" data-icon="arrow-l">Back</a>
</div>
<div data-role="content">
<ul data-role="listview">
<!--
<li><img src="/FirstApp/assets/img/1.jpg" />2013-10-08 똥맛카레</li>
<li><img src="/FirstApp/assets/img/2.jpg" />2013-10-08 카레맛똥</li>
-->
<%
while(rs.next()){
Blob image = null;
image = rs.getBlob("lunch_image");
out.print("<li>");
//prints com.mysql.jdbc.Blob@2d58497c
out.print(rs.getBlob("lunch_image"));
//prints [B@686fdca5
//out.print(image.getBytes(1,(int)image.length()));
out.print("</li>");
}
} catch (SQLException e) {
e.printStackTrace();
}
}catch(ClassNotFoundException ce){out.println(ce);}
%>
</ul>
</div>
</div>
就像我评论的那样,
我已经检查了 blob 类型数据是否存在,但我不知道如何显示数据。如果这是 jsp-servlet 我知道我只需要这样做。
InputStream in = image.getBinaryStream();
int length = (int) image.length();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
while ((length = in.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
但我不明白这种情况。