Read Clob/BLOB and struts2clob from the struts2 front-end page

Source: Internet
Author: User

Read Clob/BLOB and struts2clob from the struts2 front-end page

When the Clob attribute value of an object is displayed through the Struts2 tag, the value of the toString method is displayed instead of the CLOB or BLOB content.

For example, the annotation in my object is:

@Lob@Column(name = "CONTENT_TEXT")public String getContentText() {return contentText;}

Front-end page reading method:
<s:property value="#entry.contentText" />
The result is as follows:
oracle.sql.CLOB@1077e76

To properly display CLOB or BLOB content. The clob or blob conversion method must be added to the action.

public String getClob(Clob c){Reader reader = null;StringBuffer sb = new StringBuffer();try {reader = c.getCharacterStream();BufferedReader br = new BufferedReader(reader);String temp = null;while ((temp=br.readLine()) != null) {sb.append(temp);}} catch (Exception e) {}finally{if (reader!=null) {try {reader.close();} catch (IOException e) {}}} return sb.toString();}
The frontend page call is changed

<s:property value="%{getClob(#entry.contentText)}" /></span>

In this way, the clob content can be normally displayed. blob is similar, but the reading method is changed to binary stream reading.


Struts2 reads blob data (image) from the database)

1. Reader rd = rs. getCharacterStream (1); and Blob blob = rs. getBlob (1); 1 represents the column number, indicating that it will return data from the first column
2. Only one image is displayed on your front-end. That's because your SQL language restricts the use of only one image: select GoodsImage from table_goods where GoodTypeID = 1

Struts2 reading data from the database

Get the data you need in the action, put it in the action class attribute, and add the public access method. After the action is executed, it jumps to the page, you can directly use $ {} or <s: property> to access this property.

I don't think you have any basic concepts...

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.