...">

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

<% 
String a="abc";
Srting b="xyz";
String c=a+"\n"+b;
%>

      

I want to show String c

in HTML table like this:

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

      

I want to get the following:

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

      

But I get this:

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

      

Is there anything I could do with scriplet to achieve this?

+3


source to share


4 answers


Html has a tag <br>

for page breaks. So you can paste it into java code instead \n

:



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

      

+5


source


Try using <br/>

instead"\n"



Line c = a + "<br/>"

+ b;

+1


source


From your design,

You can just do it like

<table>
  <tr>
    <td><%= a %></td>
  </tr>
  <tr>
    <td><%= b %></td>
  </tr>
</table>

      

to display it in strings. Using <br/>

in a table is pointless.

If you intend to display multiline td

,

Plus, scripts have been discouraged for a decade. Please read How to avoid Java code in JSP files?

+1


source


String a = "abc", b = "xyz";

"+ b);%>
0


source







All Articles