27 12 / 2011
Difference between / and /* in servlet mapping
/ means the servlet is the default servlet for the app
/* is used for path mapping and captures all requests to the app. In essence, every request goes through this servlet even requests for JSPs. JSP cannot be used with a servlet mapping of /*
Never use /* in the servlet mapping.
This thread by far has the best explanation http://www.coderanch.com/t/366340/Servlets/java/servlet-mapping-url-pattern-vs
16 12 / 2011
Scalate is good but not usable
Scalate is an awesome template engine and i really mean that. Its written in Scala and just fabulous in the way that it supports multiple template languages like HAML(Scaml),Jade and Mustache over a common interface.
Its simple enough to understand and is really easy to write HTML templates using Jade/Scaml without using an IDE. The documentation is decent enough to convince you to use it on your project. Some of the Scala web frameworks like Scalatra use it as the default TE.
But if you are going to use it on a Java web project, be warned. You will end up writing Scala code to support simple operations like iterating a collection. I like the idea that the template gets translated to Scala code but to write Scala foreach or for loops for iterating collections every time is ridiculous. Writing templates should be easy and common tasks should already be provided.
Sure, Scalate lets you call Scala functions and it looks like custom tags in JSP, but the fact that YOU have to write that function makes it look less sexier. I don’t like JSP, i live with it because it has JSTL. Scalate should come up standard set of functions for mundane tasks.
If you are using Spring MVC / Struts 2, both provide tag libraries for JSP. Using Scalate, you have to create your own set of functions to mirror the tag-lib functionality, which is certainly not what you want to do.
Thinking about Scalate for Java web projects, my advice is stay away.
14 9 / 2011
Escaping ID selector in jQuery
If you are using a framework like JSF/Struts which generates ids like
id=”form:myButton” or id=”form.myIput[1]” and want to use these ids in jQuery, it would complain “unrecognized expression :myButton”.
Escape it with double backslashes like this
$(“#form\\:myButton”) or $(“#form\\.myInput\\[1\\]”)
Permalink 1 note