首页 > 其他 > 详细

struts2 action 返回图片流

时间:2014-11-26 18:02:12      阅读:294      评论:0      收藏:0      [点我收藏+]

数据库为mssql zp字段为image类型

java代码

 OutputStream out = null;
          try
          {
              String contenttype = "image/jpeg";
              ActionContext context = ActionContext.getContext();  
               // HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);  
                HttpServletResponse response = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);  
                
                response.setContentType(contenttype);               
                out = response.getOutputStream();                
           Statement stmt=con.createStatement();
           String sql="select top 1 zp from table_1 ";
           ResultSet rs=stmt.executeQuery(sql);
           //byte []by =rs.getBytes(0);
           while(rs.next()){
               out.write(rs.getBytes("ZP"));
           } 
          }
          catch(SQLException ee){
           
          }
          finally {
              out.flush();
                out.close();
          }        

struts.xml

<action name="bb" class="test.tt" method="getimage2">                              
        </action>

index.jsp

 <img name="inputName"  id="inputName" src="bb.action"/>

 

struts2 action 返回图片流

原文:http://www.cnblogs.com/lvlv/p/4123611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!