没见过即用out输出流又用ServletOutputStream输出流的,用一个吧:ResultSet rs =null;
PreparedStatement pstm = null;
int i = 0;
ServletOutputStream os = response.getOutputStream();
try{
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
if(rs == null)
System.out.println("从数据库中取不出。");
}
catch(Exception e)
{
e.printStackTrace();
}
os.write("<form method='post' action = 'TestJsp.jsp'>".getBytes());
os.write("<center><table border = '1' width='150' height='150'><tr>".getBytes());
while (rs.next())
{
InputStream in = rs.getBinaryStream("car_photo");
byte[] buf = new byte[10240];
int len = 0;
os.write("<td width='148' height='135'>".getBytes());
while ( (len = in.read(buf)) != -1)
{
System.out.println(len);
os.write(buf, 0, len);
}
// os.flush();
// os.close();
os.write("</td>".getBytes());
i++;
if (i % 3 == 0)
{
os.write("</tr><tr>".getBytes());
}
os.flush();
}
PreparedStatement pstm = null;
int i = 0;
ServletOutputStream os = response.getOutputStream();
try{
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
if(rs == null)
System.out.println("从数据库中取不出。");
}
catch(Exception e)
{
e.printStackTrace();
}
os.write("<form method='post' action = 'TestJsp.jsp'>".getBytes());
os.write("<center><table border = '1' width='150' height='150'><tr>".getBytes());
while (rs.next())
{
InputStream in = rs.getBinaryStream("car_photo");
byte[] buf = new byte[10240];
int len = 0;
os.write("<td width='148' height='135'>".getBytes());
while ( (len = in.read(buf)) != -1)
{
System.out.println(len);
os.write(buf, 0, len);
}
// os.flush();
// os.close();
os.write("</td>".getBytes());
i++;
if (i % 3 == 0)
{
os.write("</tr><tr>".getBytes());
}
os.flush();
}
解决方案 »
- 关于静态的ArrayList的异常,求解决
- 出现org.hibernate.TransactionException: Transaction not successfully started
- axis1.x wsdl 生成java代码
- 谁有javaeye.com的账户 帮忙下个东西 谢谢了
- 在jdk6.0+Eclipse3.2+MyEclipse的JSF开发环境中下列语句出现错误
- 如何在Sun\AppServer中配置JNDI呀?
- what is IDA PRO?
- mm求教,高手赐招!急。。。急。。。(jwsdp1.3 上生成的web service例子在weblogic7.0上部署的问题)
- 第二轮面试顺利通过,谢各位版友(2)...
- SWT FileDialog怎么在打开的对话框中选中多个文件?
- 一个main中的exception,请问如何解决 谢谢了
- 大型论坛与普通论坛有什么区别吗?
ServletOutputStream os = response.getOutputStream();
这句提到while循环的前面,不要在循环体里面反复的调用