如何使 JSP 标记文件不忽略所有空格?
我真的被这个难住了。 我想输出一个列表,并让标记文件处理逗号、单数与复数等,但是当我显示列表时,它完全忽略空格,所以一切都像这样一起运行。 我尝试使用 HTML 实体“thinsp”、“ensp”和“emsp”(我不能使用“nbsp”,这些实体必须被破坏),但它们在 IE 上都非常宽,除了 Thinsp 太瘦了在其他一切上。
编辑: 行不通的。 标签的输出根本没有空格。 尽管 JSP 中的任何内容都有正常的间距。 显然,我可以将所有内容都放在 JSP 中,但这是在多个 JSP 上运行的代码,因此标记文件会很有意义。
I'm really stumped on this one. I want to output a list and have the tag file take care of commas, singular versus plural, etc. but when I display the list it completely ignores whitespace so everythingrunstogetherlikethis. I tried using the HTML entities "thinsp", "ensp" and "emsp" (I can't use "nbsp", these have to be breaking), but they're all hideously wide on IE except thinsp which is way too skinny on everything else.
Edit:
won't work. The output from the tag has no spaces at all. Although any content in the JSP has normal spacing. Obviously I could just put everything in the JSP but this is code that goes on multiple JSPs, so tag files would make a lot of sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这实际上是 EL 解析器中的一个错误,导致 EL 表达式之间的空格被吃掉。 例如,
将打印为(假设它们返回与其属性名称完全相同的字符串值):
我记得之前曾在某处报告过此问题,但我现在似乎无法找到它。 到目前为止,您可以使用 JSTL
c:out
标记来修复它:它正确地打印为:
It's actually a bug in the EL parser which causes spaces in between EL expressions to be eaten. E.g.
would get printed as (assuming that they returns the very same String value as its property name is):
I recall that this issue was reported somewhere before, but I can't seem to find it right now. As far now you can fix it by using JSTL
c:out
tag:which correctly get printed as:
也许将jsp内容放在html
Maybe put the jsp content in an html
<pre>
tag?This seems to me to be the right thing to do as the list is pre-formatted content.
我使用
实体而不是空格,但一般来说,我认为这很糟糕,要么所有空白都被吃掉,必须使用实体进行修改,要么生成的 HTML 代码中有大量空间。
I used
entity instead of space but generally I think this sucks that either ALL whitespace is eaten and one has to hack with entities or you have vast space in the generated HTML code.
所以你是说你的标签根本没有打印出空格?
打印出来有空格吗?
您可以发布代码以及如何使用它的简短示例吗?
So you are saying your tag doesn't print out white space at all?
Is there any whitespace for it to print out?
Can you post the code, and a short example of how you use it?