Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

newline dropped by HTML

Thread view: 
jupiter - 18 Mar 2007 17:48 GMT
I am stumped.  I send Java String to an HTML processor method that
renders the text into pretty browser text.  Fine, it works, it is
so colorful and so dashing that it takes my breath away.

But wait, what about multi-line text sent to the HTML method as a
single String?   The HTML appears to be dropping the newlines that
I append to the Java String.  I append "\n" after each line is
read, concatenate the lines, and send them off to the processor.  I
end up with a one-liner as if I never had appended the newlines.

Of course this works when output goes to display.  Of course!

I think I have to come up with a scheme to add the HTML tags before
sending it to the HTML processor method.  Or something like that.
I don't even know if that makes sense since tags added on a line by
line basis may screw things up worse.

Here's a sample line from the HTML processor method where I insert
a String called answerText.  You can see that sending "extra" HTML
is a bit of a weird concept, but I have no clue what else to try.

sb.append("<a href=\"#\" onMouseover=\"div" + divNum +
".innerHTML=\'" + answerText + "\'\" onMouseout=\"div" + divNum +
".innerHTML=\'\'\">\n");
jupiter - 18 Mar 2007 17:48 GMT
>I am stumped.  I send Java String to an HTML processor method that
>renders the text into pretty browser text.  Fine, it works, it is
[quoted text clipped - 22 lines]
> ".innerHTML=\'" + answerText + "\'\" onMouseout=\"div" + divNum +
> ".innerHTML=\'\'\">\n");

I just tried sending the String like this:
tempText = (tempText + "<font color=white>\nXXX\n</font>");

It actually inserts the XXX and it changes the color, but do you
THINK it will obey \n?  Not on your life.
Xiaochuan Fang - 18 Mar 2007 17:53 GMT
jupiter 写道:
>> I am stumped.  I send Java String to an HTML processor method that
>> renders the text into pretty browser text.  Fine, it works, it is
[quoted text clipped - 28 lines]
> It actually inserts the XXX and it changes the color, but do you
> THINK it will obey \n?  Not on your life.

What is the 'HTML processor'?Browser?
Are you talking about '<BR>'?
jupiter - 18 Mar 2007 18:15 GMT
> jupiter дµÀ:
>
> What is the 'HTML processor'?Browser?
> Are you talking about '<BR>'?

Aha! Thanks.

(I knew that, right?)
pkoerner@online.de - 18 Mar 2007 17:55 GMT
That's standard HTML behaviour. Any number of whitespace-Chars (\n,
\r, tab, space, ...) not marked as PCDATA is compacted to only one
whitespace. To get around this use &nbsp; for spaces and <br /> for
new-lines.

Peter
jupiter - 18 Mar 2007 18:15 GMT
> That's standard HTML behaviour. Any number of whitespace-Chars
> (\n,
[quoted text clipped - 5 lines]
>
> Peter

Big Aha!

Red faced, I limp back to insert the stupid tag that I could have
inserted instead of the gargantuanly stupid (is that a word?)
<font> tag.
Chris - 18 Mar 2007 19:11 GMT
>> That's standard HTML behaviour. Any number of whitespace-Chars
>> (\n,
[quoted text clipped - 11 lines]
> inserted instead of the gargantuanly stupid (is that a word?)
> <font> tag.

Another useful tag is <pre>, for "preformatted". Wrap it around your
text with line breaks and the browser will break the lines as expected.
jupiter - 18 Mar 2007 23:32 GMT
> Another useful tag is <pre>, for "preformatted". Wrap it around
> your text with line breaks and the browser will break the lines
> as expected.

That is sweet, Chris. I had not heard of that tag.
Martin Gregorie - 19 Mar 2007 12:33 GMT
>> Another useful tag is <pre>, for "preformatted". Wrap it around
>> your text with line breaks and the browser will break the lines
>> as expected.
>
> That is sweet, Chris. I had not heard of that tag.

"HTML for the World Wide Web" by Elizabeth Castro. Get it. Read it. Then
you'll have a working grasp of HTML.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Oliver Wong - 21 Mar 2007 15:54 GMT
>>> Another useful tag is <pre>, for "preformatted". Wrap it around your
>>> text with line breaks and the browser will break the lines as
[quoted text clipped - 4 lines]
> "HTML for the World Wide Web" by Elizabeth Castro. Get it. Read it. Then
> you'll have a working grasp of HTML.

   Alternatively, check out http://www.w3schools.com/.

   Castro's book may be excellent -- I wouldn't know, as I've never read
it. On the other hand, w3school is free, and it was "good enough" for
learning HTML for me.

   - Oliver
Martin Gregorie - 22 Mar 2007 14:48 GMT
>>>> Another useful tag is <pre>, for "preformatted". Wrap it around your
>>>> text with line breaks and the browser will break the lines as
[quoted text clipped - 9 lines]
> it. On the other hand, w3school is free, and it was "good enough" for
> learning HTML for me.

The reasons I like Castro's book are that it:

- gives a clear, well-written tutorial introduction to all the
  main features of HTML.
- documents common proprietary extensions, portability issues
  and work-rounds
- has examples that only need an ASCII editor and a web browser to
  work through them.
- contains excellent reference sections that link back to
  relevant parts of the tutorials. Its the only reference I need.
- is cheaper than most computer books.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.