Paolo
Paolo

Reputation: 2472

JSTL: How to print a newline

How can I print a newline ("\n" or "\r\n" or "\n\r"). Which is the right one to be understood by a browser?) using JSTL or EL? I want to really print a newline (not a <BR>), since I need to place it in a javascript section in a HTML file.

Upvotes: 1

Views: 9238

Answers (5)

BryanH
BryanH

Reputation: 6062

You are asking the wrong question in your main post, and you later added it in a comment (perhaps you should edit your post to reflect the information in the comment?):

I need to put a \n after a // <![CDATA[ to end the comemnt before actaul JS code starts.

The easiest way to fix your issue is to comment out the CDATA using a block comment like this:

/* <![CDATA[ */

This will allow you to continue your code on the same line and it will not be part of the comment.

Example

/* <![CDATA[ */ var foo = "var";alert( foo ); /* ]]> */

Upvotes: 1

santiago
santiago

Reputation: 171

Even simpler:

<%= '\n' %>

Upvotes: 1

kamal
kamal

Reputation: 7

Try the below concept and it works.

<c:set var="String1" value="line1 line2 line3 line4" />
<c:set var="String2" value="${fn:split(String1, ' ')}" />
<c:set var= "new" value="<br />" />

<c:out value="${String2[0]}${new}" escapeXml="false" />
<c:out value="${String2[1]}${new}" escapeXml="false" />
<c:out value="${String2[2]}${new}" escapeXml="false" />
<c:out value="${String2[3]}${new}" escapeXml="false" />

Upvotes: -1

Paolo
Paolo

Reputation: 2472

Simple, solution is just not to use JSTL/EL

<% out.print("\n"); %>

Upvotes: 2

Jens
Jens

Reputation: 6383

Try the xml entities for this: &#10; for a newline and &#13; for carriage return.

Upvotes: 3

Related Questions