aspose file tools*
The moose likes Servlets and the fly likes Missing newline Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Missing newline" Watch "Missing newline" New topic
Author

Missing newline

Sasikanth Malladi
Ranch Hand

Joined: Nov 04, 2000
Posts: 175
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

Joined: Feb 07, 2007
Posts: 185
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18655
    
    8

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

Joined: Nov 04, 2000
Posts: 175
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

Joined: Jan 10, 2002
Posts: 61420
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Missing newline