日期:2014-05-18 浏览次数:20758 次
<%@ page contentType="text/html;charset=GBK"%> <%request.setCharacterEncoding("GBK");%> <%@ page import="java.util.*" %> <%@ page import="javazoom.upload.*"%> <% if (MultipartFormDataRequest.isMultipartFormData(request)) { MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request); Hashtable files = mrequest.getFiles(); if ((files != null) || (!files.isEmpty())) { UploadFile file = (UploadFile) files.get("uploadfile"); String file_name = file.getFileName(); PreparedStatement pstmt=con.prepareStatement("insert into blobtest values(1,?)"); FileInputStream fis = new FileInputStream(file.getInpuStream()); //把输入流设置为预处理语句的对象。 pstmt.setBinaryStream(1, fis, (int)file.length()); //执行更新 pstmt.executeUpdate(); pstmt.close(); } }
------解决方案--------------------
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<jsp:useBean id="sqlConn" scope="application" class="dgeip.OraconnDg"/>
<%
Connection con=null;
Statement stmt=null;
try{
con=sqlConn.getConnection();
stmt=con.createStatement();//数据库的连接
String sql="select * from dd_model WHERE model_no='07002'";
ResultSet rs=stmt.executeQuery(sql);
rs.next();
InputStream in=rs.getBinaryStream("shoe_pic");
response.reset();
response.setContentType("image/jpeg");
byte[] b=new byte[1024];
int len;
while((len=in.read(b))>0)
{
response.getOutputStream().write(b,0,len);
}
out.clear();
out = pageContext.pushBody();
in.close();
rs.close();
stmt.close();
con.close();