| Author |
String buffer issue when dispalying a new line
|
Makhana Jiggu
Greenhorn
Joined: Nov 09, 2005
Posts: 11
|
|
When i run the following code, the output is not displaying in a new line but displays everything in a same line. Any advice please. I'm struggling but cant get it solved. this is kind of urgent any help is great... StringBuffer s = new StringBuffer(4000); s.append("Name: " + custNamerequestedAmt + "\n"); s.append("Name: " + custNamerequestedAmt+"\n"); //s.append('\n'); // also tried this but did not work s.append("Phone: " + custPhone + "\n"); s.append("Email: " + custEmail + "\n"); s.toString(); Also I want to bold the headings of the column the name and phone, how can i acheive this.
|
Jiggu
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24044
|
|
Hi, Welcome to JavaRanch! Is this in a servlet or JSP, so the output is going to HTML? If so, then you have to use explicit "<BR>" elements as line breaks; "\n" will be ignored. Of course, it would be better to use a "<TABLE>" element to structure your whole table; while you're at it, you could use "<TH>" (table header) elements for the headers, suitably styled.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Makhana Jiggu
Greenhorn
Joined: Nov 09, 2005
Posts: 11
|
|
I'm not using servlet. I'm using java and output is displayed in a jsp page using jsp custom logic tag.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24044
|
|
Right, a JSP. So the output is HTML. As I said, newlines aren't significant in HTML; you have to use HTML tags for formatting. Your code is going to have to do something like this: Of course, there are better ways to do this, but you get the idea.
|
 |
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
my two cents: from java 5 on, use the StringBuilder instead of the StringBuffer. Its not synchronized, which is a completely unnecessary functionality in most use-cases. many greetings, jan
|
 |
Makhana Jiggu
Greenhorn
Joined: Nov 09, 2005
Posts: 11
|
|
|
I have to use existing jsp page where i need to pre populate all these values in a text area in a new line. Is there any other solution?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
Here's what you need to do: 1. Decide what HTML you need to produce. 2. Write a JSP to produce that HTML. Sounds like you haven't done step 1 properly because you aren't clear on how newlines work in HTML. I thought you didn't have to change them to <br> in a text area but I'm not clear on that either. So just create some little HTML pages in a text editor and see what works.
|
 |
 |
|
|
subject: String buffer issue when dispalying a new line
|
|
|