out.println() 不起作用
我有作业,必须在其中使用 scriptlet, 我需要使用 int out 对象在 jsp 页面中创建新行 我尝试使用
<%
out.println();
out.newLine();
%>
但两者都不起作用!我想用
out.flush()
但是没用!!
I have homework which I have to use scriptlets in ,
I need to make new line in my jsp page usint out object
I tried to use
<%
out.println();
out.newLine();
%>
but both doesn't work !!! I treid to use
out.flush()
but it doesn't work!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许
out.println("
就是您所追求的。 (请记住,您在其中查看 jsp 页面的浏览器将脚本的输出解释为 HTML,这基本上会忽略换行符。)");
您可以查看页面的源代码查看 jsp 页面实际生成的内容。
如果您真的想查看jsp脚本的逐字输出,您可以这样做
Perhaps
out.println("<br>");
is what you're after. (Remember that the browser in which you're viewing the jsp-page in, interprets the output of your script as HTML, which basically ignores newline characters.)You can look at the source of the page to see what the jsp-page actually generates.
If you really want to see the verbatim output of the jsp-script, you could do
@Alaa -
out.newLine()
确实有效。它只是没有执行您期望的操作...假设您的 JSP 正在生成 HTML 页面。当您使用
out.newLine()
时,它会向您生成的内容流添加一个换行符。如果您使用网络浏览器中的页面查看源代码,您可以看到换行符。但 HTML 文档中的换行符通常不会导致浏览器呈现的显示页面出现换行。要让浏览器在显示的页面中呈现换行符,通常*需要输出一个
元素。* - 实际上,还有其他方法可以获得涉及 CSS 等的换行符的视觉效果。在
中,原始换行符确实被渲染为换行符。
@Alaa -
out.newLine()
does work. It just doesn't do what you are expecting it to do ... assuming that your JSP is generating an HTML page.When you use
out.newLine()
, it adds a newline character to the content stream that you are generating. If you use view source on the page in your web browser you can see the newline character.But a newline character in an HTML document typically does not result in a line break in the displayed page as rendered by a browser. To get the browser to render line break in the displayed page, you typically* need to output a
<br />
element.* - Actually, there are other ways to get the visual equivalent of a line break involving CSS, etcetera. And within a
<pre>...</pre>
a raw newline character does get rendered as a line break.请记住,JSP 代码正在输出 HTML。然后浏览器将呈现 HTML。呈现 HTML 时,HTML 中的单个空行可能不会在屏幕上显示为空行。
您需要在浏览器中检查 HTML 源代码并查找空行。或者尝试输出更重要的 HTML 来验证 JSP scriptlet 是否正常工作,如下所示:
Remember the JSP code is outputting HTML. The HTML will then be rendered by the browser. A single blank line in HTML may not be shown as a blank line on the screen when the HTML is rendered.
You need to either examine the HTML source in the browser and look for the blank line. Or else try output more significant HTML to verify the JSP scriptlets are working like: