• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String buffer issue when dispalying a new line

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Makhana Jiggu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic