This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Missing newline

 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All, I'm sending plain text content to a browser from my servlet.

When I view the page source, here's what I see:
IP_address: 146.128.73.73
Subnet: 146.128.73.0

Subnet_mask: 255.255.255.0
Router1: 146.128.73.1
Router2: 146.128.73.2

However, when the browser displays this information, it lops off the newlines and shows it all in one line thus:
IP_address: 146.128.73.73 Subnet: 146.128.73.0 Subnet_mask: 255.255.255.0 Router1: 146.128.73.1 Router2: 146.128.73.2

How do I force the browser to respect my newlines? I do not want to send it in HTML as this page will be read by wget and parsed and I want to keep it simple.

THanks,
Sashi
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's how a browser would behave,the formatting is usually ignored and it's necessary to use html break tags.

Regards,
Srikkanth.M
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set the content type to "text/plain"?
If not, the browser will assume that you're sending HTML and interpret it as such.

NOTE: MSIE often ignores content headers and treats things as HTML no matter what you specify.

For that reason, you might be better off wrapping your plain text in a set of <pre></pre> tags which tells the HTML interpreter to include whitespace.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sasikanth Malladi:
How do I force the browser to respect my newlines? I do not want to send it in HTML as this page will be read by wget and parsed and I want to keep it simple.
I would suggest, if you are designing this to be processed by wget, then you should not be too concerned about how a browser displays it.
 
Sasikanth Malladi
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To revisit an old topic, I'd like to see a solution.

Even though I'm designing this page to be read by wget/curl, I'd like to see the line breaks so that it's easy to be passed into a filter via a pipe.

I have set the content type to "text/plain" and it still doesn't help. I've noticed that a few pages generated by Perl/php do seem to preserve the newlines.

I can't think of a reason why Java would behave differently.

Anybody faced this issue before?

Thanks,
Sashi
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a response gets to the browser, it doesn't matter whether Java was used on the back end or not. The browser has no way of knowing. Therefore, the response must not be in the format that you think it is. The next step is for you to obtain a tool that will allow you to inspect the response as returned to the browser and see what's wrong with it.

Firefox has a few plugins that can do this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic