我有以下字段:
mysql> select content from campaign where cid = 489;
+------------------------------+
| content |
+------------------------------+
| hi
how are you?
wie gehts? |
+------------------------------+
并希望在html上显示,但是当我使用
时<sql:transaction dataSource="${dataBase}">
<sql:query var="tAdmin">
SELECT content FROM campaign
</sql:query>
</sql:transaction>
<c:forEach var="row" items="${tAdmin.rows}" varStatus="totalRow" step="1">
<c:set var="myContent" value="${row.content}"/>
</c:forEach>
然后:
<script language="JavaScript" type="text/JavaScript">
element.innerHTML='${myContent}';
</script>
它在浏览器上显示为空白。任何的想法?提前谢谢
答案 0 :(得分:0)
您可以尝试这样的事情:
选择替换(temp,'
',CHR(13)|| CHR(10))INTO outString from dual;
这是Oracle SQL btw。
因此,您可以将当前的SQL(SELECT内容FROM campaign)编写为子查询:
从双重选择替换(选择内容来自广告系列,'&lt; br /&gt;',CHR(13)|| CHR(10));
答案 1 :(得分:-1)
我终于找到了这个EL wiki stackoverflow并做了类似以下的事情:
1. Create new line to <br/> conversion file so-called Functions.java under WEB-INF/org/global:
package org.global;
public final class Functions {
private Functions() {}
public static String nl2br(String string) {
return (string != null) ? string.replace("\r\n", "<br/>") : null;
}
}
2. Create new TLD file so-called Functions.tld under WEB-INF/tld or wherever TLD files reside:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1">
<tlib-version>1.1</tlib-version>
<short-name>New_Functions</short-name>
<uri>http://global.org/functions</uri>
<function>
<name>nl2br</name>
<function-class>org.global.Functions</function-class>
<function-signature>java.lang.String nl2br(java.lang.String)</function-signature>
</function>
</taglib>
3. Add this line on the respective .jsp file :
<%@taglib uri="http://global.org/functions" prefix="f" %>
and finally use the function prefix :
${f:nl2br(row.content)}