Why not just write your own variation?

String getParm(HttpServletRequest req, String name)
{
    return(getParm(req, name, ""));
}

String getParm(HttpServletRequest req, String name, String defValue)
{
    String s = req.getParameterValue(name);
    if (null == s)
        s = defValue;

    return(s);
}

Then just pass in the default value you want:

        String postParam = getParm(req, "postParm", "0");

Bob


On Thursday, March 18, 1999 5:59 PM, Christopher Goldman [SMTP:[EMAIL PROTECTED]] wrote:
> My two cents...
>
> I don't have a problem with getParameterValues(), even when I know that I
> only have a single value.  I set the default value for my variable when I
> declare it:
>
> String postParam = "[EMAIL PROTECTED]";
>
> Then I just wrap my call in a try-catch block:
>
> try
> {
>     postParam = request.getParameterValues( "postParam" )[0];
> }
> catch( NullPointerException npe ) {}
>
> I think it's a matter of style; I prefer not to set my default values inside
> an if-null block.  It seems much easier to me to be able to look at the
> variable decalarations at the top of my method.  It is just as safe as the
> if-null test, and when the parameter has been posted, which is most of the
> time, it seems to me that it will execute marginally faster than checking
> for null every time.  I'm sure if this is not correct, someone will let me
> know.
>
> Chris
>
> > -----Original Message-----
> > From: James Duncan Davidson
> > Sent: Thursday, March 18, 1999 3:30 PM
> >
> > > > getParameter returns the same value as getParamterValues[0]
> > >
> > > Except that if the parameter does not exist, you'll get an error when
> > > attempting getParameterValues[0], while with getParameter you get a null
> > > which you can safely check.
> >
> > True enough. I was just trying to say that the getParameterValue has a
> > well defined behavior as to which element out of the array it will return.
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to