Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

<% 
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?

like image 223
Rey Rajesh Avatar asked Dec 15 '25 06:12

Rey Rajesh


2 Answers

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

String c=a+"<br>"+b;
like image 99
Nailgun Avatar answered Dec 16 '25 21:12

Nailgun


Try to use <br/> instead of "\n"

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

like image 37
atish shimpi Avatar answered Dec 16 '25 22:12

atish shimpi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!