Reputation: 461
I am having problem displaying a text with multiple lines. For example, the user can type their text in a textarea
in a registration form and the text can be of more than one line i.e. he can hit the Enter (return) key to insert line breaks.
On one page, if I want to show the text that he typed and I use a textarea to display (with EL
), it displays the way user had entered initially.
But on another page I need this text be shown in paragraph format (using <p>
tag). On this page, when I display the value that the user entered while registering, it does not have the line breaks i.e. it displays in a single line rather than with multiple lines as was entered by the user.
I already tried displaying the text through EL
within a <p>
tag and using a <c:out>
tag of the JSTL within a <p>
tag.
Some code that I tried:
Trial-1:
<p>${product.description}</p> //Doesn't show line breaks
Trial-2:
<p><c:out value="${product.description}" /></p> //Doesn't show line breaks too
How can I fix this?
Upvotes: 1
Views: 1460
Reputation: 4474
Did you view the source sent to the browser ? Please try
<p><pre>${product.description}</pre></p>
Upvotes: 5
Reputation: 11698
Right now I can think of something as to replace the \r\n
sequence in the product.description
string with <br />
with help of scriptlets
or fn
JSTL (function) tag
Idea Courtesy: SO Answer.
Upvotes: 1