[ACCEPTED]-out.println() does not work-jsp

Accepted answer
Score: 15

Perhaps out.println("<br>"); is what you're after. (Remember 7 that the browser in which you're viewing 6 the jsp-page in, interprets the output of your script as HTML, which basically ignores 5 newline characters.)

You can look at the 4 source of the page to see what the jsp-page 3 actually generates.

If you really want to see the 2 verbatim output of the jsp-script, you could 1 do

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

// ...

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

@Alaa - out.newLine() does work. It just doesn't do what 12 you are expecting it to do ... assuming 11 that your JSP is generating an HTML page.

When 10 you use out.newLine(), it adds a newline character to 9 the content stream that you are generating. If 8 you use view source on the page in your 7 web browser you can see the newline character.

But 6 a newline character in an HTML document 5 typically does not result in a line break in the 4 displayed page as rendered by a browser. To 3 get the browser to render line break in 2 the displayed page, you typically* need to 1 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.

Score: 3

Remember the JSP code is outputting HTML. The 8 HTML will then be rendered by the browser. A 7 single blank line in HTML may not be shown 6 as a blank line on the screen when the HTML 5 is rendered.

You need to either examine the 4 HTML source in the browser and look for 3 the blank line. Or else try output more 2 significant HTML to verify the JSP scriptlets 1 are working like:

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

More Related questions