Added a getParameter() that returns a default string if the desired parameter

is not specified.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1720 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2005-10-18 18:50:33 +00:00
parent ba033e20ad
commit ebb34d206d
@@ -56,7 +56,6 @@ public class ParameterUtil
String value = req.getParameter(name); String value = req.getParameter(name);
if (value == null) { if (value == null) {
return returnNull ? null : ""; return returnNull ? null : "";
} else { } else {
return value.trim(); return value.trim();
} }
@@ -74,7 +73,6 @@ public class ParameterUtil
{ {
return parseFloatParameter( return parseFloatParameter(
getParameter(req, name, false), invalidDataMessage); getParameter(req, name, false), invalidDataMessage);
} }
/** /**
@@ -89,7 +87,6 @@ public class ParameterUtil
{ {
return parseIntParameter( return parseIntParameter(
getParameter(req, name, false), invalidDataMessage); getParameter(req, name, false), invalidDataMessage);
} }
/** /**
@@ -164,6 +161,17 @@ public class ParameterUtil
return set; return set;
} }
/**
* Fetches the supplied parameter from the request. If the parameter does
* not exist, <code>defval</code> is returned.
*/
public static String getParameter (
HttpServletRequest req, String name, String defval)
{
String value = req.getParameter(name);
return StringUtil.blank(value) ? defval : value.trim();
}
/** /**
* Fetches the supplied parameter from the request and converts it to * Fetches the supplied parameter from the request and converts it to
* an integer. If the parameter does not exist, <code>defval</code> is * an integer. If the parameter does not exist, <code>defval</code> is