tags in java string I am trying to insert line break tags in some text and display it on a web page. characters are...">

How to insert <br/"> tags in java string

I am trying to insert line break tags
in some text and display it on a web page. <and> characters are converted to &lt;and &gt;, and tags are displayed as text on the web page.

The text looks like this when I select it from the database (I output it to SYSOUT):

version 12.4
service timestamps debug datetime
service timestamps log datetime
service password-encryption

Then I run it through this little filter:

public DevConfigs getDevConfig() {

    String config = devConfig.getConfig();

    Pattern pattern = Pattern.compile(".$", Pattern.MULTILINE | Pattern.DOTALL);
    Matcher matcher = pattern.matcher(config);
    String newConfig = matcher.replaceAll("<br />");

    devConfig.setConfig(newConfig);
    return this.devConfig;
}

Here is the webpage (this is a Seam application using facelets):

<rich:tab label="Config">
    hello<br />
    there<br />
    #{devConfig.config}
</rich:tab>

And the source of the page is as follows:

hello<br />
there<br />
&lt;br /&gt;
&lt;br /&gt;

version 12.&lt;br /&gt;
service timestamps debug datetim&lt;br /&gt;
service timestamps log datetim&lt;br /&gt;
service password-encryptio&lt;br /&gt;
&lt;br /&gt;

As you can see, my tag is displayed as HTML characters, not as tags. What do I need to do to insert line break tags at the end of each line of text?

Tdr

+3
4

( ) HTML- . h:outputText ( RichFaces ) escape, false.

<h:outputText value="#{bean.property}" escape="false" />
+7

, . / java String. <br> HTML . JSP.

Struts ", false, HTML:

Java

String text = "This line will <br> break";

JSP

<bean:write name="object" property="attribute" filter="false"/>
+1

Java, , ,

<rich:tab label="Config">
    hello<br />
    there<br />
    #{devConfig.config}
</rich:tab>

<rich:tab label="Config">
    <![CDATA[
    hello<br />
    there<br />
    ]]>
    #{devConfig.config}
</rich:tab>

:

<rich:tab label="Config">
    <![CDATA[
    hello
    there
    ]]>
    #{devConfig.config}
</rich:tab>

?

0

, . \n <br />?

public DevConfigs getDevConfig() {

    String config = devConfig.getConfig();
    String newConfig = config.replace("\n", "<br />");
    devConfig.setConfig(newConfig);
    return this.devConfig;
}

. , Preg Dialect... &lt;br /&gt;. Javascript .
, .

. .$ , char ( ).

0

Source: https://habr.com/ru/post/1727392/


All Articles