Formatting JSP 1
Making a JSP page is not always easy, and it’s the unexpected details that are tricky. I usually get an HTML mockup with static data from a designer, and have to turn that into something dynamic. Sometimes that involves writing a few droplets, but mostly it’s just knowing where the data is organized and pulling things in from the bean properties.
My weakness is that I’m not a good designer. Before I can edit the mockup and start putting dynamic data in, I have to figure out where the table begins and ends (so I can iterate over rows), figure out what the CSS style is for errors, and generally mash the page up. Designers, as a rule, don’t place a high premium on making sure that the tags are indented right:
<tr> <td>Foo</td></tr> <tr>
You can use things like JTidy to clean up HTML, but if you’re dealing JSP or any kind of markup, nothing will work. At least, that’s what I thought until JSPFormat.
JSPFormat will take any kind of JSP and will correctly indent BOTH the java code (if someone was mad enough to use raw java for iteration) and the HTML code. It will even format Javascript. There are plugins for IDEA, Eclipse and JBuilder. And as far as I can tell, it seems to be free, although it’s worth paying for.
The only bug I’ve found with it is that it introduces whitespace between anchor tags, so that foo will be formatted as
<a href="foo.html"> foo </a>
In short, JSPFormat is massively useful and I recommend it to anyone who works with JSP.
I got an email about my JSP being improperly formatted the other day. It wasn’t my fault though! Someone had used tabs instead of spaces (I always use spaces), and the formatting looked fine to me. Someone else opened the file though, and the tabs were wider than my space indentations. Ugh.
If you want to tidy your html on the way out, check out mod_tidy for Apache 2. Its really fast!