java类中的方法:
创建一个tld文件里面内容如下:
在jsp页面我们加入tld
/**
* 解析BLOB大对象to String
* @param blob
* @return
*/
public static String getStrings(Blob clob) throws IOException, SQLException {
try {
if(clob == null)
return "";
InputStream is = clob.getBinaryStream();
StringBuffer sb = new StringBuffer();
int readedBytes;
int bufferSize = 4096;
do {
byte[] bytes = new byte[bufferSize];
readedBytes = is.read(bytes);
if (readedBytes > 0) {
String readed = new String(bytes, 0, readedBytes, "gb2312");
sb.append(readed);
}
} while (readedBytes == bufferSize);
is.close();
return sb.toString();
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
创建一个tld文件里面内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<tlib-version>1.0</tlib-version>
<short-name>elf</short-name>
<function>
<description>取Blob数据内容函数gb2312</description>
<name>blobToString</name>
<function-class>org.platform.common.utils.ONGLUtils</function-class>
<function-signature>
java.lang.String getStrings(java.sql.Blob)
</function-signature>
<example>${elf:blobToString(blob)}</example>
</function>
</taglib>
在jsp页面我们加入tld
<%@ taglib prefix="elf" uri="/WEB-INF/elfunc.tld" %>
<html>
<body>
${elf:blobToString(content)} content是从数据库里面取出的BOLB大对象
</body>
<html>