2

我有以下领域:

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>

它在浏览器上显示为空白。任何想法?提前致谢

4

2 回答 2

1

你可以尝试这样的事情: select replace(temp, '
', CHR(13)||CHR(10)) INTO outString from dual;

这是 Oracle SQL 顺便说一句。

因此,您可以将当前的 SQL(从活动中选择内容)编写为子查询:

选择替换(从广告系列中选择内容,'<br />',CHR(13)||CHR(10))从双重;

于 2013-05-08T21:27:53.727 回答
0

我终于找到了这个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)}
于 2013-05-10T22:45:29.487 回答