Struts2 Hibernate displays multiple images on a JSP page

Source: Internet
Author: User

Recently need to traverse a JSP page above a number of pictures, usually do more is a string integer and other types of traversal, the picture is binary and the original commonly used types are very different.

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;

}

}

The main code in the action

/**

* Find all the stamps according to the user 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";

}


/**

* Display photo Information

*/

Public String Showseal () {

Bbfseal seal = manage.loadseal (ID);

Instantiates a byte array stream, storing the photo bytes in the table

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" is used for output binary streams in file downloads

<param name= "ContentType" ></param>

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

</result>

</action>

TOSEAL.JSP Core Code

</tr>

<s:iterator value= "Bbfseals" >


<tr >

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

<!--display photo information, SRC Specify action and pass in 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;

}

}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.