471,854 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,854 software developers and data experts.

Line break in Java

I am currently learning JSP and was wondering how you would implement a line break?

Expand|Select|Wrap|Line Numbers
  1. <%              java.util.Date d1;
  2.            java.util.Date d2;
  4.            d1= new java.util.Date();
  5.            d2 = new java.util.Date();
  7.            out.println(d1);
  8.            out.println("\n");
  9.            out.println(d2);
I thought the line would do the trick but it didn't. The out put is:

This is the heading

This is the body

Fri Aug 14 23:04:55 PDT 2009 Fri Aug 14 23:04:55 PDT 2009
Basically I wanted to have the two dates in two lines.

Anyone any idea? Thanks.
Aug 14 '09 #1
7 25783
11,448 Expert 8TB
You are printing HTML code right? A "<br>" tag prints a new line in HTML, so simply print that tag.

kind regards,

Aug 14 '09 #2
Yes its HTML but I dont think you can insert any HTML or non-Java stuff between <% %>

I tried it didn't work. But outside that yes, <br> works like it normally would.
Aug 14 '09 #3
Oh I think I get what you mean,

Some thing like this:

date 1 is : <%= d1%> <br>
date 2 is : <%= d2%>

and putting the remainder in a scriplet <% %>.

Aug 14 '09 #4
13,262 8TB
You don't really want to use those scriplets in JSPs these days.
Better keep all the Java code in 'pure' servlets or in separate helper Java functions.
You can use EL to access objects in various scopes too.
Aug 14 '09 #5
11,448 Expert 8TB
Simply do a out.println("<br>") just as the OP was doing with his dates?

kind regards,

Aug 14 '09 #6
156 100+
Aug 18 '09 #7
I think the problem here is that JSP pages. They require HTML style line breaks (like any HTML documents). So, try using "<br />" instead of "\n".
Aug 18 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Roland Dalmulder | last post: by
5 posts views Thread by Wai Yip Tung | last post: by
6 posts views Thread by Nurchi BECHED | last post: by
1 post views Thread by questionz_99 | last post: by
4 posts views Thread by deerchao | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.