Notes by Dr. Xi
Displaying keyword search results 1 - 10
Created by Dr. Xi on February 13, 2012 20:48:56
Last update: February 13, 2012 20:48:56
When you insert an attribute in JSP:
<%@ taglib uri="http://tiles.apache.org/tags-tiles...
you must define the attribute in tiles definitions:
<definition name="/home" template="/WEB-INF/templa...
Otherwise you'll get runtime exception.
The ignore attribute, which defaults to false , will suppress the runtime exception when the attribute is not defined in tiles definition:
<%@ taglib uri="http://tiles.apache.org/tags-tiles...
Created by Dr. Xi on February 13, 2012 16:03:58
Last update: February 13, 2012 16:05:19
Microsoft provides free downloadable Windows images to support IE browser compatibility testing, just google Internet Explorer Application Compatibility VPC Image .
These VMs run on Microsoft's Windows Virtual PC . According to MS:
You can technically have a base image which never expires although you will never be able to permanently save any changes on these images for longer than 90 days.
Created by Dr. Xi on February 01, 2012 12:55:28
Last update: February 01, 2012 12:55:28
You can define environment variables in the Tomcat context.xml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<Context...
which is equivalent to the following in web.xml :
<env-entry>
<env-entry-name>varName</env-entr...
In Java code, the variable can be looked up like this:
// import javax.naming.Context;
// import javax...
Created by Dr. Xi on July 15, 2011 09:25:15
Last update: July 15, 2011 09:25:15
Some methods to search for a substring within a string:
To know that a substring indeed exists within a string:
boolean found = wholeString.contains(substring);
To find where the substring is contained:
int index = wholeString.indexOf(substring);
If the substring is regex:
boolean match = wholeString.matches(".*" + substri...
Case insensitive match: convert both whole string and substring to lowercase, then compare. Or, use case insensitive flag for regex.
Test code:
import java.util.regex.*;
public class Stri...
Created by Dr. Xi on July 11, 2011 12:04:52
Last update: July 11, 2011 12:04:52
From the Java Language Specification : Because some type information is erased during compilation, not all types are available at run time. Types that are completely available at run time are known as reifiable types . A type is reifiable if and only if one of the following holds: It refers to a non-generic type declaration. It is a parameterized type in which all type arguments are unbounded wildcards. It is a raw type. It is a primitive type. It is an array type whose component type is reifiable. For example: int is a reifiable type (primitive type) List is a reifiable type (raw type) List<?> is a reifiable type (parameterized type with unbound wildcards) List<String> is not a reifiable type (generic type) Class<?> is...
Created by Dr. Xi on June 27, 2011 15:49:00
Last update: June 28, 2011 11:13:35
You should drop the generics notation when looking up a method by signature:
import java.util.*;
import java.lang.reflect.Me...
In fact, Class.forName("java.util.List<java.lang.String>") fails with ClassNotFoundException !
However, all information about parameterized types are not lost at runtime. The Java reflection API does provide these methods to get information about parameterized types at runtime:
Method.getGenericExceptionTypes
Method.getGenericParameterTypes
Method.getGenericReturnType
for which the non-generic counterparts are:
Method.getExceptionTypes
Method.getParameterTypes
Method.getReturnType
Created by Dr. Xi on June 22, 2011 15:15:15
Last update: June 22, 2011 15:15:15
There's no such thing as an immutable byte array in Java. What we are trying to achieve here is to protect the byte array inside the object from which it is being returned. We want to caller to have the contents of the byte array, but not be able to change the contents inside the object. The trick is to return a copy instead of the internal reference:
public class ReturnByteArray {
public stati...
Created by Dr. Xi on May 17, 2011 21:14:58
Last update: May 17, 2011 21:17:58
Read certificate one at a time from BufferedInputStream :
// import java.security.cert.*;
public void rea...
Read all certificates from a file as a collection:
public void readCertificates(File f) throws Except...
Created by Dr. Xi on May 03, 2011 14:27:15
Last update: May 03, 2011 14:28:06
The XML schema for a contact might look like this:
<?xml version="1.0" encoding="UTF-8"?>
<schema ...
With XML digital signatures , a Signature element is inserted inside the contact element after the contact file is signed. Like this:
<?xml version="1.0" encoding="UTF-8" standalone="n...
which no longer validates with the original schema.
The schema should be updated to (with the addition of digital signature namespace, schema import and Signature ref ):
<?xml version="1.0" encoding="UTF-8"?>
<schema ...
Created by Dr. Xi on April 20, 2011 21:44:15
Last update: May 02, 2011 20:56:58
The String.format() method provides versatile formatting capabilities. This tutorial tries to present these capabilities in a accessible manner. The format string A format string can contain zero, one, or more format specifiers . The general form of a format specifier is:
%[argument_index$] [flags] [width] [.precision]co... where things in square brackets are optional, and conversion is a character indicating the conversion to be applied to the corresponding variable value. The only required characters in the format specifier is the percent sign % and the conversion character. A simple example: public static void simpleFormat() { System.out... The Argument index The argument index is specified by a number, terminated by the dollar sign $ . The same argument may be repeated multiple times in a format string. Unindexed...