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
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
,
- How to show multiline text in a table cell
- The width of a <td> is narrower when I use <br> in it on a fixed width <table>. Why?
Plus, scripts have been discouraged for a decade. Please read How to avoid Java code in JSP files?
+1
source to share