java中字servlet在数据库中取到的图片二进制流怎么显示在jsp页面上的table中
DataBaseManegerdata=null;Connectionconn=null;PreparedStatementps=null;ResultSetrs=nul...
DataBaseManeger data = null;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Statement stmt = null;
ServletOutputStream op = null;
InputStream in = null;
public ServletOutputStream getTitlePic(HttpServletResponse response) throws ServletException, IOException {
conn = data.getDataBaseManeger().getConnection();
String sql = "select ftitlepic from tnews ORDER BY FNEWSDATE DESC limit 1";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
response.reset();
if (rs.next()) {
in = rs.getBinaryStream("ftitlepic");
op = response.getOutputStream();
int len;
byte[] buf = new byte[88888888];
while ((len = in.read(buf)) != -1) {
op.write(buf, 0, len);
}
op.flush();
}
}catch (SQLException e) {
e.printStackTrace();
}finally{
try{
op.close();
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
closeConn();
return op;
}
public void closeConn(){
try {
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
stmt.close();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
怎么把字节流数组传到jsp前台页面的table中td里面的Img表现上并显示
因为我将图片取出来显示了,但是我jsp页面上的其他东西都不显示了
就一张字节流生成的图片! 展开
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Statement stmt = null;
ServletOutputStream op = null;
InputStream in = null;
public ServletOutputStream getTitlePic(HttpServletResponse response) throws ServletException, IOException {
conn = data.getDataBaseManeger().getConnection();
String sql = "select ftitlepic from tnews ORDER BY FNEWSDATE DESC limit 1";
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
response.reset();
if (rs.next()) {
in = rs.getBinaryStream("ftitlepic");
op = response.getOutputStream();
int len;
byte[] buf = new byte[88888888];
while ((len = in.read(buf)) != -1) {
op.write(buf, 0, len);
}
op.flush();
}
}catch (SQLException e) {
e.printStackTrace();
}finally{
try{
op.close();
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
closeConn();
return op;
}
public void closeConn(){
try {
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
stmt.close();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
怎么把字节流数组传到jsp前台页面的table中td里面的Img表现上并显示
因为我将图片取出来显示了,但是我jsp页面上的其他东西都不显示了
就一张字节流生成的图片! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询