# A tip: multiline JSP comments
I don't normally do tips, and this is probably fairly obvious to most, but I'll go ahead anyway because I don't really have anything else intelligent to blog about tonight.
The proper way to comment JSPs is to enclose comments in <%-- --%> tags. The only minor annoyance is that the Jasper compiler (and perhaps others, perhaps it's the standard), will still send a newline for each line of JSP comment, so a multiline JSP comment leaves the HTML page with a big chunk of whitespace.
This isn't the end of the world, and you have enough wonky HTML formatting with other JSP tags inserting newlines and mucking up indentation, but I'm always a bit iffy about really mangled HTML. Clean JSP markup is leagues more important than clean HTML, but if it won't hurt your JSP, then better-looking HTML is worth aiming for. Now, I think most modern literature will tell you that Java code in JSP's is evil, and that plain old <% %> tags have no place in modern JSPs. However, the quickest way to get around the miles of whitespace problem, if you consider it to be a problem, is to use normal tags, and use normal Java comments, like so:
<% /*
This
is
a
multiline
comment
*/ %>
That generates only two lines in the HTML page. I don't recall having seen anyone do this before, but I stumbled across a project which did this while looking at a few open-source web apps when I was trying to see how people handled copyright info in their JSPs. I far prefer it to the three main alternatives I found, which seem to be (a) ignore the problem, (b) limit copyright notice to a line or two, and (c) put copyright notices at the end of the page where the whitespace is less noticeable.
I don't think I'd do this in a work environment, where following expected conventions is probably more important than HTML aesthetics, but for a small pet project like, say, the blog, I think it's nifty enough to be worth doing.
File under: java : {2007.02.18 - 23:15}