简体   繁体   English

out.println()不起作用

[英]out.println() does not work

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 我有功课,我必须使用scriptlets,我需要在我的jsp页面中创建新行usint out对象我试图使用

<%
out.println();
out.newLine();
 %>

but both doesn't work !!! 但两者都不起作用! I treid to use 我很想使用

out.flush()

but it doesn't work!! 但它不起作用!!

Perhaps out.println("<br>"); 也许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.) (请记住,您在其中查看jsp页面的浏览器会将脚本的输出解释为HTML ,这基本上会忽略换行符。)

You can look at the source of the page to see what the jsp-page actually generates. 您可以查看页面的来源以查看jsp页面实际生成的内容。

If you really want to see the verbatim output of the jsp-script, you could do 如果你真的想看到jsp脚本的逐字输出,你可以这样做

out.println("<html><body><pre>");

// ...

out.println("</pre></body></html>");

@Alaa - out.newLine() does work. @Alaa - out.newLine() 确实有效。 It just doesn't do what you are expecting it to do ... assuming that your JSP is generating an HTML page. 它只是没有做你期望它做的事情......假设你的JSP正在生成一个HTML页面。

When you use out.newLine() , it adds a newline character to the content stream that you are generating. 当您使用out.newLine() ,它会向您生成的内容流添加换行符。 If you use view source on the page in your web browser you can see the newline character. 如果在Web浏览器的页面上使用视图源,则可以看到换行符。

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. 但HTML文档中的换行符通常不会导致浏览器呈现的显示页面中的换行符。 To get the browser to render line break in the displayed page, you typically * need to output a <br /> element. 为了让浏览器呈现在显示的页面断行,你通常需要*输出<br />元素。

* - Actually, there are other ways to get the visual equivalent of a line break involving CSS, etcetera. * - 实际上,还有其他方法可以获得涉及CSS等等的换行符的视觉效果。 And within a <pre>...</pre> a raw newline character does get rendered as a line break. <pre>...</pre> ,原始换行符被渲染为换行符。

Remember the JSP code is outputting HTML. 请记住,JSP代码正在输出HTML。 The HTML will then be rendered by the browser. 然后,HTML将由浏览器呈现。 A single blank line in HTML may not be shown as a blank line on the screen when the HTML is rendered. HTML呈现时,HTML中的单个空行可能不会在屏幕上显示为空行。

You need to either examine the HTML source in the browser and look for the blank line. 您需要在浏览器中检查HTML源代码并查找空白行。 Or else try output more significant HTML to verify the JSP scriptlets are working like: 或者尝试输出更重要的HTML来验证JSP scriptlet的工作方式如下:

<%
    out.println("<p>hello</p>");
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM