• 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

JSP out.println

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to display multiline data retrieved from database as such..with spaces in a jsp page ..but out.println always trims and display it..im using tomcat as server..is there any other way to prevent trimming

thanx in advance,
sujatha
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really ? Wouldn't that be that browser who removes the spaces ?
Try to use nbsp in your println.
http://www.sightspecific.com/~mosh/WWW_FAQ/nbsp.html

(I wouldn't rely on spaces to format the output.)
[ July 19, 2006: Message edited by: Satou kurinosuke ]
 
Sujatha Rangarajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it trims the given string also..what do u mean browser trimming
 
Sujatha Rangarajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also data is from database ..so it cannot be predicted whether the data would contain space or not..
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The out.println method trims nothing.
It only adds a new line character to the end.
(out.print doesn't add a new line).

To better understand Satou's post, try viewing the HTML source from your browser's "Menu -> View -> View Source" option. You will see that all the whitespace is still there.

Browsers ignore whitespace when rendering HTML becuase they are supposed to.
There are HTML tags for spaces and new lines.
Use &nbsp; for a space and <br /> for a line break.
You will need to parse your database results and substitute spaces and line breaks with these symbols.

Two other alternatives are:
1.) Use the <pre> your text </pre> tags.
2.) Display the literal text in a <textarea>your text</textarea> control.
[ July 19, 2006: Message edited by: Ben Souther ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic