如何使JSP标记文件不忽略所有空白? [英] How do I make JSP tag files NOT ignore all whitespace?

查看:70
本文介绍了如何使JSP标记文件不忽略所有空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很为难.我想输出一个列表,并让标记文件处理逗号,单数或复数等.但是当我显示列表时,它完全忽略了空格,因此所有内容都像这样运行.我尝试使用HTML实体"thinsp","ensp"和"emsp"(我不能使用"nbsp",这些必须被破坏),但它们在IE上的范围都很窄,除了Thinsp太瘦了在其他一切上.

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.

将无法正常工作.标签的输出根本没有空格.尽管JSP中的任何内容都具有正常的间距.显然,我可以将所有内容放入JSP中,但这是可以在多个JSP上运行的代码,因此标记文件很有用.

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.

推荐答案

这实际上是EL解析器中的一个错误,导致EL表达式之间的空格被占用.例如

It's actually a bug in the EL parser which causes spaces in between EL expressions to be eaten. E.g.

${bean.foo} ${bean.bar} ${bean.waa}

将被打印为(假设它们返回与其属性名称相同的String值):

would get printed as (assuming that they returns the very same String value as its property name is):

foobarwaa

我记得以前曾在某个地方报道过此问题,但现在似乎找不到.到目前为止,您可以使用JSTL c:out标记对其进行修复:

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:

<c:out value="${bean.foo} ${bean.bar} ${bean.waa}" />

正确打印为:

foo bar waa

这篇关于如何使JSP标记文件不忽略所有空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆