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;
- }
Java Portlet 图片渲染
本文介绍了一段 Java 代码,该代码通过调用存储过程获取数据库中的图片数据,并将其输出到客户端。主要涉及参数处理、数据库交互及图片输出流程。
1万+

被折叠的 条评论
为什么被折叠?



