469,315 Members | 1,802 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

Line break in Java

61
Hi
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;
  3.  
  4.            d1= new java.util.Date();
  5.            d2 = new java.util.Date();
  6.  
  7.            out.println(d1);
  8.            out.println("\n");
  9.            out.println(d2);
  10.  
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 25408
JosAH
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,

Jos
Aug 14 '09 #2
Alien
61
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
Alien
61
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 <% %>.

Thanks.
Aug 14 '09 #4
r035198x
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
JosAH
11,448 Expert 8TB
@Alien
Simply do a out.println("<br>") just as the OP was doing with his dates?

kind regards,

Jos
Aug 14 '09 #6
karthickkuchanur
156 100+
System.getProperty("line.separator");
Aug 18 '09 #7
esami
1
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 harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.