jsp:include vs jsp include directive

In JSP technology you can include another page in two modes: using jsp:include tag:

<jsp:include page=”dir/file.jsp” flush=”true”/>

Or with the include file directive:

<%@ include file=”dir/file.jsp” %>

What’s the difference?

In the first case the page is called and compiled at run-time and in the second case is called and compiled at compiled-time.

I notice that a jsp file is re-compiled everytime it changes.

For example if you are using the inlcude directive and you modify the included page you still see the same previously compiled result. You need to recompile the father jsp in order to recompile the child jsp. In this case you need to change (or touch) the both.

Using the jsp:include it is not necessary because everytime the both jsp are re-compiled.

You say: “Ok, but I’m sure I’ll not change the included/child jsp”.

Perfect! Change the param flush to false.

Here you can find more jsp directives.

java.util.Enumeration vs java.util.Iterator

The next example print, using the standard output, all the java.lang.String Object included in a java.util.Map using a java.util.Iterator

Iterator oIterator = oMap.values().iterator();
while(oIterator.hasNext()){
String[] theParam = (String[])oIterator.next();
String theValue = (String)oMap.get(theParam[0]);
System.out.println("\n= param: " + theParam[0] + " --> " + theValue);
}

The next one use the java.util.Enumeration to print a java.util.Hashtable

if(!oHashtable.isEmpty()){
Enumeration oEnumeration = oHashtable.keys();
while(oEnumeration.hasMoreElements()){
String theParam = (String)oEnumeration.nextElement();
String theValue = oHashtable.get(theParam);
System.out.println("\n=param: " + theParam + "=" + theValue);
}
}

Notice that it needs an if to check the status of the Hashtable because the method .keys() can throw a java.lang.NullPointerException.

Java String Capitalize

When I was looking for first time the method to capitalize a Java String, I was searching in the Sun Official API but… there isn’t.

Strange not?

No problem this is the code to capitalize a Java String:

String mystring = (mystring.substring(0, 1).toUpperCase() + mystring.substring(1).toLowerCase()).trim();

You can also download it from Javamarco google code repository