How to display a string with new line character in a HTML page using scriplets?

Rey Rajesh picture Rey Rajesh · Nov 6, 2014 · Viewed 16.9k times · Source
<% 
String a="abc";
Srting b="xyz";
String c=a+"\n"+b;
%>

I want to display String c in a HTML table like this:

<table>
  <tr>
    <td><%= c %></td>
  </tr>
</table>

I want to get this:

--------
| abc  |
| xyz  |
--------

But I get this:

------------
| abc xyz  |
------------

Is there anything I could do with the scriplet to acheive this?

Answer

Nailgun picture Nailgun · Nov 6, 2014

Html has<br>tag for page breaks. So you can insert it in java code instead of \n:

String c=a+"<br>"+b;