码迷,mamicode.com
首页 > 其他好文 > 详细

struts2 action 返回图片流

时间:2014-11-26 18:03:14      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   os   sp   java   数据   

数据库为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 返回图片流

标签:style   blog   http   io   color   os   sp   java   数据   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!