aspose file tools*
The moose likes JSP and the fly likes JSP out.println Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP out.println" Watch "JSP out.println" New topic
Author

JSP out.println

Sujatha Rangarajan
Greenhorn

Joined: Jul 19, 2006
Posts: 23
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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 ]

[My Blog]
All roads lead to JavaRanch
Sujatha Rangarajan
Greenhorn

Joined: Jul 19, 2006
Posts: 23
it trims the given string also..what do u mean browser trimming
Sujatha Rangarajan
Greenhorn

Joined: Jul 19, 2006
Posts: 23
also data is from database ..so it cannot be predicted whether the data would contain space or not..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP out.println