473,573 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Line break in Java

61 New Member
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 25959
JosAH
11,448 Recognized Expert MVP
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 New Member
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 New Member
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 MVP
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 Recognized Expert MVP
@Alien
Simply do a out.println("<b r>") just as the OP was doing with his dates?

kind regards,

Jos
Aug 14 '09 #6
karthickkuchanur
156 New Member
System.getPrope rty("line.separ ator");
Aug 18 '09 #7
esami
1 New Member
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

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

Similar topics

1
22406
by: Roland Dalmulder | last post by:
Hello all, In my PHP script I put a text file into a string. Part of that string is read, changed and removed. The while loop continuest to extract the next part of the string. This goes all fine with one exception. When there is a line break in the second string that has the extract of the first string, it cannot find the words I am...
5
10891
by: Wai Yip Tung | last post by:
When I do for line in fp: the line string usually has a '\n' at the end. In many cases I don't want the line break character. I can trim it using if line.endswith('\n'): line = line Given I do it so frequently I wonder if there is some builtin way to say I
5
29497
by: Kathryn | last post by:
Good morning! I am having a problem with a span. I have items, of which I only want to show the first X characters on the screen. If the user prints the page, I want the entire item to print. Thanks to Els, I have a way to do this, see below, directly from the View Source: This is a long piece of text. This is a long piece of text. ...
6
16237
by: Nurchi BECHED | last post by:
Hello, All! I have created an application with a multiline textbox on the form. When I press a button, it has to show something and then break the line and show something else. I tried "\n", ((char)13) and ((char)10) - they don't work. When I enter a break by hand (just press enter) and run through each character in that string, the line...
1
6906
by: questionz_99 | last post by:
How would I specify line breaks of specific height? For example, if I wanted to insert a 6-point line break, what would the CSS code look like? Obviously, I'd like something more specific than the <br> tag. Thanks.
3
17303
by: lmawler | last post by:
Hi all, I know when I do data entry, I can force a line break in a text box by using Control & Enter. I'm trying to insert a line break in a field (that behaves like Control Enter) from VB. Anyone know the command for this? Here's what I want to do: rst2("Change") = rst2("Change") & **LINE BREAK *** & "Autopropagated Change to..."
4
5799
by: deerchao | last post by:
Hi, I'd like to render colorful text with word wrap on screen (kind of inline <fonttag to change text color in html), but run into the line break problem. Graphics provides several DrawString methods with line break features, but I can't make them draw different colors within one string, And if I split the string into several part, so I...
1
4605
by: mccalla | last post by:
Hi all, Tricky question. I know how to remove line break characters and spaces by using the code below: $message =~ s/\n//g; $message =~ s/\s//g;
7
4192
by: jeddiki | last post by:
Hi, I am using a function called htmlwrap() which states that it does NOT add a "<br>" to the 70 character line so that it forces a line wrap. ( the script safely wraps long words without destroying html tags which wordwrap has a tendency of doing! )) What I want to do is add that line break so that it DOES force a line wrap - but I am...
0
7750
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7674
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8039
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3708
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3708
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2170
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.