java 代码
- public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req, RenderResponse res) throws Exception {
- //存储过程的参数
- String pkValue = ParamUtil.getString(req, "pkValue");
- String tableName = ParamUtil.getString(req, "tableName");
- String pkName = ParamUtil.getString(req, "pkName");
- String imgColumnName = ParamUtil.getString(req, "imgColumnName");
- HttpServletResponse response = PortalUtil.getHttpServletResponse(res);
- //调用存储过程返回记录集
- ResultSet rs = ProductUtil.getImgByPK(Integer.parseInt(pkValue), tableName, pkName, imgColumnName);
- rs.next();
- //获得图片信息,强制转换为java.sql.Blob类型
- Blob blob=(Blob)rs.getBlob(1);
- if(blob!=null){
- //输出
- response.setContentType("image/jpeg");
- OutputStream outs = response.getOutputStream();
- InputStream pi = blob.getBinaryStream();
- int blobsize = (int)blob.length();
- byte[] blobbytes = new byte[blobsize];
- int bytesRead = 0;
- while ((bytesRead = pi.read(blobbytes)) != -1) {
- outs.write(blobbytes, 0, bytesRead);
- }
- pi.close();
- outs.flush();
- }
- return null;
- }