gpt4 book ai didi

java - JSP 文档/JSPX : what determines how tabs/space/linebreaks are removed in the output?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:04:14 24 4
gpt4 key购买 nike

我有一个格式良好的“JSP 文档”(“XML 中的 JSP”),当网页生成并发送给用户时,一些换行符被删除。

现在真正奇怪的部分是:显然“主”.jsp 总是所有它的换行符被删除但是对于从主 .jsp 包含的任何后续 .jsp,换行符似乎被随机删除(一些有,其他没有)。

例如,如果我正在查看 Firefox 提供的网页并要求“查看源代码”,我会看到生成的内容。

那么,什么决定何时/如何保留/删除换行符?

这只是我编造的一个例子......你能强制一个 .jsp 来服务这个吗:

<body><div id="page"><div id="header"><div class="title">...

或者这个:

<body>
<div id="page">
<div id="header">
<div class="title">...

?

我认为删除换行符是为了节省带宽,但如果我想保留它们怎么办?如果我想保留与 .jsp 文件中相同的 XML 缩进怎么办?

这可行吗?

编辑

按照 skaffman 的建议,我查看了生成的 .java 文件,“主要”文件没有很多 out.write 但没有一个写制表符或换行符。与该文件相反,我从主 .jsp 中包含的所有文件都有很多行,例如:

out.write("\t...\n");

所以我想我的问题保持不变:是什么决定了如何在输出中包含/删除制表符/空格/换行符?

最佳答案

根据 JSP specification :

JSP.6.2.3 Semantic Model

...

To clearly explain the processing of whitespace, we follow the structure of theXSLT specification. The first step in processing a JSP document is to identify thenodes of the document. Then, all textual nodes that have only white space aredropped from the document; the only exception are nodes in a jsp:text element,which are kept verbatim. The resulting nodes are interpreted as described in thefollowing sections. Template data is either passed directly to the response or it ismediated through (standard or custom) actions.

所以,如果你想保留空白,你需要把想要的部分包裹在<jsp:text>中。 .

关于java - JSP 文档/JSPX : what determines how tabs/space/linebreaks are removed in the output?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2935093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com