struts2 hibernate 在jsp頁面上面顯示多個圖片

來源:互聯網
上載者:User

標籤: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;

}

}




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.