java 在jsp中插入多个空格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12013119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inserting Multiple spaces in jsp
提问by Soham
I am trying to insert multiple spaces between two words in jsp.
我想在jsp中的两个单词之间插入多个空格。
Is there a way to insert spaces without using   
mulitple times?
有没有办法在不使用  
多次的情况下插入空格?
Kindly help. Thank you.
请帮助。谢谢你。
回答by dsh
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).
HTML 定义多个空格的序列与单个空格具有相同的意义。还有不间断空格,由字符实体 表示
。请注意,使用空格不是实现布局和对齐的好方法(如果这是您的实际目标)。
http://www.w3.org/TR/html401/struct/text.html
http://www.w3.org/TR/html401/struct/text.html
For all HTML elements except PRE, sequencesof white space separate "words"
对于除 PRE 之外的所有 HTML 元素,空格序列分隔“单词”
(empahsis mine)
(强调我的)
回答by Chander Shivdasani
回答by Benjamin Cox
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.
通常认为在 HTML 中粘贴大量 nbsp 是不明智的,因为间距是一种格式问题,而不是 HTML 或数据本身的语义组件。
Instead, I usually try to use CSS to format things like that:
相反,我通常尝试使用 CSS 来格式化类似的东西:
.spacey { word-spacing: 20px; }
<p class="spacey">This is some text with 20 pixels between each word.</p>
回答by jsshah
In the JSP of your choice do the following at the bottom
在您选择的 JSP 中,在底部执行以下操作
<%!
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