static < T > T getParameter ( final ServletRequest pReq , final String pName , final Class < T > pType , final String pFormat , final T pDefault ) { // Test if pDefault is either null or instance of pType if ( pDefault != null && ! pType . isInstance ( pDefault ) ) { throw new IllegalArgumentException ( "default value not instance of " + pType + ": " + pDefault . getClass ( ) ) ; } String str = pReq . getParameter ( pName ) ; if ( str == null ) { return pDefault ; } try { return pType . cast ( Converter . getInstance ( ) . toObject ( str , pType , pFormat ) ) ; } catch ( ConversionException ce ) { return pDefault ; } }
Gets the value of the given parameter from the request converted to an Object . If the parameter is not set or not parseable the default value is returned .