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

code block linebreak  RSS feed

 
Wagner Narde
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume I have this jsp...

-----------
<%@ page import="java.util.*" %>
<%@ page import="com.mycomp.bla.util.*" %>
<html>
<body>
Mooo.
</body>
</html>
-----------

...rendered as:

-----------
(blank line)
(blank line)
<html>
<body>
Mooo.
</body>
</html>
-----------

I would like to remove these blank lines. Is it possible without putting everybody at the same line?
Ruby on Rails framework provides a simple solution, by putting a "-" at the end of code tag, like <%= something -%>, but I cannot find a way with jsp.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. Why do you care?

If you you care deeply you could write a servlet filter that wraps the response and removes the excess whitespace.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Tomcat (you didn't say) go to the web.xml file under the conf directory and search for the trimSpaces attribute in JspServlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, yeah, if you wanna get container-specific! :roll:

Seriously, I didn't know of that setting Ben -- really good info!

Most people wouldn't care about the whitespace (which is why I asked for your motivation). If bandwidth is your concern, you'd be better off instituting a gzip compression filter than worrying about whitespace.

But if you're using tomcat, you can get both using Ben's tip!
 
Wagner Narde
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I only wanna output readable html code. Thanks for your tip, Ben!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!