Posts

Showing posts from February, 2012

OMG you put Java code in the view!!

One of the unique joys of developing anything with Java Server Pages is encountering the Scriptlet Police. Scriptlets, as you probably know, are little bits of Java code embedded into the JSP. I think of JSPs as being servlets turned inside out. In a servlet, everything is Java by default, but you can throw in some HTML in the form of strings. In a JSP, on the other hand, everything is HTML by default, but you can throw in some Java in the form of scriptlets, like this: <ul> <% for (Foo foo: listOfFoos) { %> <li><%= foo.getName() %></li> <% } %> </ul> But God forbid you do this and then admit it on a mail group or message board. Any hint that you're actually putting Java code in your JSP will attract a lecture from the Scriptlet Police, for example: Question: "I am a complete JSP beginner. I am trying to use a java.util.List in a JSP page. What do I need to do to use classes other than ones in java.lang?" Hel