请问mssql2000的img图像类型的数据如何在web页面上显示? SQL Server 2000的img类型存储的是图片,可是用PHP无法在网页上显示,显示出来的是乱码,img格式的记录,是以二进制的方式保存在数据库里的。不知道有没有很好的方法能够将数据库的图片记录显示在网页上,或者将图片记录转成图片也行。希望给予指点,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // 从表中得到照片到页面 public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { PreparedStatement pst = null; Connection m_conn=null; try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test"; m_conn = DriverManager.getConnection(url, "sa", "1234"); String sql = "select pic from picture where id=" + 1; pst = m_conn.prepareStatement(sql); ResultSet rs = pst.executeQuery(); if (rs.next()) { InputStream in = rs.getBinaryStream("pic");//表中图片类型的字段名 int bytesRead = 0; byte[] buffer = new byte[8192]; //设置照片格式. response.setContentType("image/gif"); //返回ServletOutputStream 对象. OutputStream outs = response.getOutputStream(); while ((bytesRead = in.read(buffer, 0, 8192)) != -1) { outs.write(buffer, 0, bytesRead); } outs.flush(); in.close(); rs.close(); } else { rs.close(); } } catch (Exception e) { e.printStackTrace(); } finally { try { pst.close(); m_conn.close(); } catch (SQLException ex) { ex.printStackTrace(); } } 我目前已经连上SQLServer了,img类型的记录也能通过php取出来。只是显示不出。你上述代码执行后没有反映,希望能够给点提示,谢谢。我用的是php,javascript。 header("Content-type: image/jpeg"); PHP如何用正则表达式匹配圆括号 PHP的变量前也能添加类型? 关于在class内部操作session的问题 求一正则表达式 传值 session_save_handle定义的事件,是自动发生还是手动控制? 数据库是utf8,为什么取出来的数据是GBK (送分,多退少补) - 怪事!!!删除不了... 如何去掉某字符的前三个 各位高手:关于phpbb直接登陆的问题,分不够再加. 关于php邮件问题! 送国际/国内域名+送网页空间+送企业邮局
public ActionForward view(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
PreparedStatement pst = null;
Connection m_conn=null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test";
m_conn = DriverManager.getConnection(url, "sa", "1234");
String sql = "select pic from picture where id=" + 1;
pst = m_conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
if (rs.next()) {
InputStream in = rs.getBinaryStream("pic");//表中图片类型的字段名
int bytesRead = 0;
byte[] buffer = new byte[8192];
//设置照片格式.
response.setContentType("image/gif");
//返回ServletOutputStream 对象.
OutputStream outs = response.getOutputStream();
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
outs.write(buffer, 0, bytesRead);
}
outs.flush();
in.close();
rs.close();
} else {
rs.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
pst.close();
m_conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}