简体   繁体   English

Servlet:不同的PrintWriter.print()和PrintWriter.println()

[英]Servlet: different PrintWriter.print() and PrintWriter.println()

HttpServletResponse response;
PrintWriter out = response.getWriter();
out.print("Hello");
out.println("HelloWorld");

My question seem silly, but In Servlet, I see that both print() and println() do same thing !!! 我的问题似乎很愚蠢,但是在Servlet中,我看到print()和println()都做同样的事情!

If you want to go to another line, you must put <br> tag at the end of String. 如果要转到另一行,必须将<br>标记放在String的末尾。

Thanks :) 谢谢 :)

println appends a new line ( \\n ) after the printed text. println在打印的文本之后添加新行( \\n )。 New lines are not interpreted within HTML, therefore you won't see a difference between the output of println and print within the rendered HTML. 在HTML中不会解释新行,因此在呈现的HTML中您不会看到printlnprint的输出之间的差异。

They don't do the same thing. 他们做的不一样。 println appends an end-of-line marker after the string. println在字符串后附加行尾标记。

The fact that that end-of-line isn't rendered by browers is another issue. 线尾不是由浏览器呈现的事实是另一个问题。 Depending on what content-type you're outputing, it could be significant or not. 根据您要输出的内容类型,它是否有意义。

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

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