Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting Multiple spaces in jsp

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.

like image 725
Soham Avatar asked Aug 17 '12 21:08

Soham


4 Answers

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)

like image 157
dsh Avatar answered Oct 08 '22 18:10

dsh


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

like image 41
Chander Shivdasani Avatar answered Oct 08 '22 20:10

Chander Shivdasani


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>
like image 35
Benjamin Cox Avatar answered Oct 08 '22 18:10

Benjamin Cox


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
like image 30
jsshah Avatar answered Oct 08 '22 19:10

jsshah