I am trying to insert multiple spaces between two words in jsp.
Is there a way to insert spaces without using   
mulitple times?
Kindly help. Thank you.
In short, no.
HTML defines that sequences of multiple spaces have the same significance as a single space. There is also the non-breaking space, represented by the character entity
. Do note that using spaces is not a good method for achieving layout and alignment (if that is your actual goal).
http://www.w3.org/TR/html401/struct/text.html
For all HTML elements except PRE, sequences of white space separate "words"
(empahsis mine)
Enclose it in a <pre>
tag.
Example:
out.println("<pre>This text has multiple spaces </pre>");
You can use it whenever you need unusual formatting. Look at the link here for more details about the tag
It's not generally considered wise to stick a ton of nbsp's in your HTML, as the spacing is a formatting concern, rather than a semantic component of the HTML or the data, itself.
Instead, I usually try to use CSS to format things like that:
.spacey { word-spacing: 20px; }
<p class="spacey">This is some text with 20 pixels between each word.</p>
In the JSP of your choice do the following at the bottom
<%!
public String getSpaces(int numSpaces)
{
StringBuffer buffer = new StringBuffer(numSpaces);
for(int i = 0; i < numSpaces; i++)
buffer.append(" ");
return buffer.toString();
}
%>
Then where you want space
This will have lot of spaces <%= getSpaces(10)%> here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With