Insert multiple spaces in jsp

I am trying to insert a few spaces between two words in jsp.

Is there a way to insert spaces without using   mulitple times?

Kindly help. Thank.

+5
source share
4 answers

In short, no.

HTML determines that sequences from multiple spaces have the same meaning as a single space. There is also an inextricable space represented by a symbolic entity  . Note that using spaces is not a good way to achieve layout and alignment (if that is your actual goal).

http://www.w3.org/TR/html401/struct/text.html

HTML, PRE, "

(empahsis mine)

+4

<pre>. :

out.println("<pre>This text has   multiple      spaces </pre>");

, .

+2

It's generally wise to stick to a ton of nbsp in your HTML, since spacing is a formatting issue, not a semantic component of HTML or data.

Instead, I usually try to use CSS to format things like this:

.spacey { word-spacing: 20px; }

<p class="spacey">This is some text with 20 pixels between each word.</p>
+1
source

In the JSP of your choice, do the following below

<%!
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 the space

This will have lot of spaces <%= getSpaces(10)%> here
+1
source

All Articles