码迷,mamicode.com
首页 > Web开发 > 详细

struts2 hibernate 在jsp页面上面显示多个图片

时间:2014-05-06 17:51:09      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:public

最近需要在一个jsp页面上面遍历出多个图片,平时做的比较多的是string integer等类型的遍历,图片是二进制的与原来常用的类型有很大的不同。

BBFSeal.java

public class BBFSeal {

private Blob content;

private String id;

private String name;

private BBFUseruser;

private Blob imageSeal;

public BBFSeal()

{

}

public BBFSeal(Blob  imageSeal, String id) {

super();

this.imageSeal = imageSeal;

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public void setContent(Blob content) {

this.content = content;

}

public Blob getContent() {

return content;

}

public void setId(String id) {

this.id = id;

}

public String getId() {

return id;

}


public void setUser(BBFUser user) {

this.user = user;

}

public BBFUser getUser() {

return user;

}

public Blob getImageSeal() {

return imageSeal;

}

public void setImageSeal(Blob imageSeal) {

this.imageSeal = imageSeal;

}

}

action中的主要代码

/**

* 根据用户id 找到所有的印章

*/

public String showSealList() {

HttpServletRequest request = ServletActionContext.getRequest();

BBFUser user = (BBFUser) request.getSession().getAttribute("user");

String uid = user.getId();

this.bbfSeals = this.manage.listSeals(uid);

return "toSealList";

}


/**

* 显示照片信息

*/

public String showSeal() {

BBFSeal seal = manage.loadSeal(id);

// 实例化字节数组流,存储表中的照片字节

inputStream = new ByteArrayInputStream(BlobToBinaryUtils

.blobToBinary(seal.getImageSeal()));

return "success";

}

struts.xml

<action name="sealselect" method="showSealList"

class="sealSelect">

<result name="toSealList">toseal.jsp</result>

</action>

<action name="showSeal" method="showSeal"

class="sealSelect">

<result name="success" type="stream">

<!-- type="stream"用于输出二进制流在文件的下载中会用到

<param name="contentType"></param>

--><param name="bufferSize">1024</param>

</result>

</action>

toseal.jsp 核心代码

</tr>

<s:iterator value="bbfSeals">


 <tr >

   <td><a  data-role="button" data-mini="true"  value=‘id‘/>‘);">

      <!-- 显示照片信息, src 指定action ,并传入 ID  -->

<img src="showSeal.action?id=<s:property value=‘id‘/>"

</a></td>

 </tr>

</s:iterator>

<tr>


public class BlobToBinaryUtils {

public static byte[] blobToBinary(Blob blob) {

InputStream is = null;

byte[] b = null;

try {

is = blob.getBinaryStream();

b = new byte[(int) blob.length()];

is.read(b);

return b;

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

is.close();

is = null;

} catch (Exception e) {

e.printStackTrace();

}

}

return b;

}

}




struts2 hibernate 在jsp页面上面显示多个图片,布布扣,bubuko.com

struts2 hibernate 在jsp页面上面显示多个图片

标签:public

原文地址:http://4747857.blog.51cto.com/4737857/1407034

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