• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP out.println

 
Sujatha Rangarajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
also data is from database ..so it cannot be predicted whether the data would contain space or not..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic