Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Compiler puts extra out.write('\n') to java file  RSS feed

 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i am using apache tomcat 5.0, When i write a JSP file and use a browser to access the file the content seems fine on the browser, However when i check the view source i see extra new line feeds.

When i see the _jsp.java file from JSP folder i see that the source code contains extra out.write('\n');

Is there some property that is appending this to the _jsp.java file.

if so please let me know how can i remove the out.write('\n')

thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jsp servlet has a trimSpaces parameter.
It's located in tomcat/conf/web.xml.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my code actually contains 3 "\n" then the actual code and finally a "\n".
this was apparent when i checked the java files generated from jsp files.

Does that mean trimspaces when set to true would not give me the result.
I really dont think so.. Those are not spaces but "\n" being written

Any other solutions?

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those entries are being copied from the JSP itself. For example if you have some directives at the beginning and they are separated by line-feeds, then those line-feeds, like any other text you put in your JSP, are sent to the response.

But you say the result looks fine in the browser, so why spend time "fixing" something that isn't a problem?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Paul said, if you are trying to keep the HTML that is sent to the browser "pretty", this is a complete and utter waste of time.

For details on why things work this way, read this JavaRanch Journal article.
 
madhup narain
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

thanks alot, i was able to get it working, Trimspaces was the problem.
My appologies to Ben for not following his post.

Thanks Guys

Regards
Madhup
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad it's working for you.
Thanks for reporting back with your solution.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!