开发者

out.println() does not work

开发者 https://www.devze.com 2023-02-07 23:43 出处:网络
I have homework which I have to use scriptlets in , I need to make new line in my jsp page usint out object

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 does开发者_JAVA百科n't work!!


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

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

// ...

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


@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.


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:

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

精彩评论

暂无评论...
验证码 换一张
取 消