Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

"include file" gives unwanted empty line  RSS feed

 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is commonly known when scripting server that you may encounter empty lines in your generated code. That's why you should attach endings and beginnings of scriplets and include statements like this
...%><%...
and not
...%>
<%...

But suddenly, after adding a feature in my server-side browser -detecting handling algortith, my xml+xslt site didn't want to generated my page because the first line was empty and the second one started with <?xml ...

Now you problably think I have/had some out.prints in my JSP file, but no!
Only booleans were declared and some Strings, no output before the generated xml header.

Looking to the, by tomcat 5.5.9, generated .java file I saw a out.println("\n") just between my <%@ include file statement and start of my scriplet (yes it's neater to use custom taglibs which I've applied in my blog section of my site).

I wasn't able to solve it so had to manually copy paste the contents of my include file in directly coming scriplet so that there was no empty line like before.

But this is not the proper way and I have to modify twice my browser-handling algorithm.

May it be some encoding problem? I was just using vi as editor. Before that I've been editing under various editing problems on a windows system. And there I've had tested various character encoding types and never had those problems. It's known that linux has 2 characters for end of line and line feed and windows only 1 but I can't imagine that is the problem.

Have any of you had the same problem?

Or any good tips how to easily convert all those scriptlets with includes into a neat working custom taglib?

Feel free to watch my site if you need and if you have any questions how (or why) don't hesitate!

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you care?
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it's taking up unnecessary bytes and screwing up the XML header which has to be on the first line for and XSLT.

That's why I care about it that much.

I hope someone else is more helpfull overthere with caring knowledge.
[ August 11, 2005: Message edited by: Jean Philippe ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to get your britches in a snitch. The reason I ask is because, in general, whitespace is completely moot and doesn't matter to the generated output. Finding out why you cared about the generated whitesapce is material input to formulate any answer.

Chill.
[ August 11, 2005: Message edited by: Bear Bibeault ]
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either move the include off the first line (if you can) or make sure your include and xml declaration look like this:

<%@ jsp directive %><%@ jsp directive %><?xml

Also make sure your included file has no extra new lines
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I wasn't clear enough about my situation. But there the directives are stuck together like glue, no space, no lines nothing, nada, niente.

That's the reason I posted it on this forum. Hoping someone could resolve my problem because it's very odd to me.

And don't worry I'm chill sorry if I was gave you that impression.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP is most often used to generate HTML which pretty much doesn't care about whitespace. And as you have seen, JSP emits lots of it.

If your output has exacting needs for whitespace control, such as RTF or XML, you may be better off emitting the output directly from a servlet rather than a JSP. I have the flat spot on the side of my head from trying to use JSP for such things in the past.

In the case of XML, it might be best to build up the DOM in memory and then serialize it to the response output.
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I think I'm going back to servlets or making custom taglib for it.

Thanks for you quick reply! Cheers mate!
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might not be the "proper" way to do it, but it might work if you use a servlet to output the xml declaration, and the JSP for everything else. It's no big deal if theres a space between the <?xml?> and the <root> element, is it?

-Yuriy
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a big deal if it"s the first line before the <?xml declaration but afterwards not a big deal for me (but little bit disturbing though).

You may call me a freak but every useless byte ... hehe

I guess I'm going for the total change in MVC and make an Custom Taglib.

I made on for my blog section on my site and it is way more flexible in my humble eyes then just a servlet. That way I can create methods and stuff and reuse them. Like OOP is meant to be.

Since I discovered that included jsp file are not compiled into the .java but included again I was really dissappointed and felt like a plain PHP-er lol.
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anybody expercience using Eclipse for making an custom taglib?
I always to it the oldschool way (vi or other plain texteditor). But maybe Eclipse is more "handy" or my way the best way, or some other...

I'm using linux so don't bother advising me m$ only based IDE's.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I discovered that included jsp file are not compiled into the .java


Well, inlcude files are compiled, just into their own implementations.

Another option you might look at is to use a servlet filter to adjust the output to your needs on the way out.
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a servlet filter? sounds interesting, but what is it?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
 
Jean Philippe
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly what I need!
Thanks a lot!
It didn't exist when I started developping servlets/jsp, or did it?

Again, thanks a lot This http://java.sun.com/products/servlet/Filters.html#70176 will keep me quiet for a little while

[ August 11, 2005: Message edited by: Jean Philippe ]
[ August 11, 2005: Message edited by: Jean Philippe ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!