在hibernate中你可以把这个字段映射成blob,然后在
web层写一个servletpublic class IconServlet extends HttpServlet { private static final String CONTENT_TYPE = "image/gif"; private transient final Log log = LogFactory.getLog(getClass()); protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { if (log.isDebugEnabled()) {
log.debug("Entering 'showIcon' method");
}
try {
String iconId = request.getParameter(Constants.ICON_ID);
if ((iconId == null) || ("".equals(iconId)))
return;
WebApplicationContext context = WebApplicationContextUtils.
getRequiredWebApplicationContext(getServletContext());
IconManager mgr = (IconManager) context.getBean("iconManager");
Icon icon = mgr.getIcon(new Long(iconId));
Blob blob = icon.getBlob();
int fileSize = (int) blob.length();
byte[] ab = blob.getBytes(1, fileSize);
response.setContentType(CONTENT_TYPE);
response.setContentLength(fileSize);
ServletOutputStream op = response.getOutputStream();
op.write(ab);
op.flush();
op.close();
} catch (Throwable e) {
log.error(e);
} }
}在jsp中 <html:img src="../icon" paramId="iconId" paramName="ware" paramProperty="iconId" border="0" align="absmiddle" width="85" height="110" />
web层写一个servletpublic class IconServlet extends HttpServlet { private static final String CONTENT_TYPE = "image/gif"; private transient final Log log = LogFactory.getLog(getClass()); protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { if (log.isDebugEnabled()) {
log.debug("Entering 'showIcon' method");
}
try {
String iconId = request.getParameter(Constants.ICON_ID);
if ((iconId == null) || ("".equals(iconId)))
return;
WebApplicationContext context = WebApplicationContextUtils.
getRequiredWebApplicationContext(getServletContext());
IconManager mgr = (IconManager) context.getBean("iconManager");
Icon icon = mgr.getIcon(new Long(iconId));
Blob blob = icon.getBlob();
int fileSize = (int) blob.length();
byte[] ab = blob.getBytes(1, fileSize);
response.setContentType(CONTENT_TYPE);
response.setContentLength(fileSize);
ServletOutputStream op = response.getOutputStream();
op.write(ab);
op.flush();
op.close();
} catch (Throwable e) {
log.error(e);
} }
}在jsp中 <html:img src="../icon" paramId="iconId" paramName="ware" paramProperty="iconId" border="0" align="absmiddle" width="85" height="110" />
解决方案 »
- Java程序如何读写配置文件?
- 为什么我打开MyEclipse时发现src 下的包少了好多
- 我想通过选中复选框 ,然后点击删除,实现删除功能,这个参数怎么传递啊
- struts2标签<s:itorator>读取list中对象属性问题
- java 登陆的验证
- [200分]部署webservice在jboss3.2.6上,当.net并发(多用户同时访问)通过它访问jboss上的项目时,老是出现返回给.net的数据错乱,详
- 请大家帮忙看看,我的这段 代码有什么问题?
- JAVA随机取数问题
- eclipse2.1.2+tomcat5.0求救????????????????
- 向各位求救了!关于XML文档存储到关系数据库的问题。
- struts标签问题
- Eclips 结合CVS 测试struts程序中的调试问题(急)
去这里搜一下!一个不错的struts论坛!
http://community.csdn.net/Expert/topic/3794/3794735.xml?temp=.6227533帮我解决问题者200分都送给他!