高手帮个忙
<%@ page contentType="text/html;charset=utf8"%><%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.awt.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head></head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost:3306/customer" +
"?useUnicode=true&characterEncoding=utf8";
Connection con = DriverManager.getConnection(url,"root","1234");
String sql = "select * from Picture where id=1";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql);
if(rs.next()) {
InputStream in = rs.getBinaryStream("picName");
ServletOutputStream op = response.getOutputStream();
int len;
byte[] buf=new byte[1024];
while((len= in.read(buf))!=-1) {
op.write(buf, 0, len);
}
op.close();
in.close();
}
rs.close();
stmt.close();
con.close();
%>
</body>
</html>
在数据库中读取图片显示在jsp页面中,但是只显示了图片的名字,并抛出异常
Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:610)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) --------------------编程问答-------------------- getOutputStream() has already been called for this response --------------------编程问答-------------------- out.clear();
out = pageContext.pushBody(); 不报错了,单jsp界面只显示图片的名称啊,我要的是显示图片,帮个忙
补充:Java , Web 开发