Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert whitespace?

Tags:

jsp

How do i insert white space in the below statement in java class but the string gets displayed in jsp page.As \n\t does not work on jsp.How do i insert white space for jsp?

sb.append("\n\tStackflow: "+"<br>");
like image 662
rkhm Avatar asked Nov 04 '22 04:11

rkhm


2 Answers

You should realize that JSP is merely a HTML code generator. Whitespace in HTML source code is by default not accounted as part of human presentation. It's by default collapsed to a single space. The average website would otherwise have looked very ugly. Copypaste for example this in browser's address bar while looking at stackoverflow.com to see the effect yourself when whitespace in HTML source code would be accounted:

javascript:$("*").css("white-space", "pre");

If you want to preserve whitespace as-is in HTML source code, you'd need to put the desired piece of HTML inside a <pre> element

<pre>
    ...
</pre>

Or to apply CSS white-space: pre; style on the parent element.

<div style="white-space: pre;">
    ...
</div>
like image 100
BalusC Avatar answered Nov 28 '22 06:11

BalusC


make use of &nbsp; (non breaking space)

sb.append("&nbsp;Stackflow: "+"<br>");
like image 38
dku.rajkumar Avatar answered Nov 28 '22 06:11

dku.rajkumar