I hear you loud and clear.  There's really no way that you could be
getting "null" from that method invocation (unless of course, your query
string looks like http://...?name1=null).

Printing the return value of getParameter("name1") will print "null" or
"", however.

Are you using the JServ module?  Send me a test servlet.

-Rob


On Wed, 14 Apr 1999, Jason Proctor wrote:

> I think you may be misunderstanding me. In the situation where I'm
> processing a request for a URL like
> 
> http://whatever.com/servlets?name1=&name2=someVal
> 
> getParameter (name1) should return either a null pointer or a blank string.
> Right now, I'm getting the string value "null", ie a four character string
> containing the characters 'n', 'u', 'l', 'l', as though somewhere someone
> is doing an implicit string conversion (eg String s = "" + null will give s
> = "null").
> 
> This is wrong, isn't it?
> 
> 
> >HttpServletRequest.getParameter("name1") should return "" in the case of a
> >URL like
> http://whatever.com/servlets?name1=&name2=someVal
> >
> >Regardless, this is still problematic, since you probably want that value
> >to be null.
> >
> >What I've done to get around this is provide my servlets with the
> >following method:
> >
> >private String getParameter(HttpServletRequest req, String parameterName)
> >throws NullParameterException {
> >     String value = req.getParameter(parameterName);
> >     if ( (value == null)  || (value.equals("") )
> >             throw new NullParameterException(parameterName);
> >     return value;
> >}
> >
> >And define a NullParameterException with a method like:
> >public String getParameterName()
> >and a constructor like the one used above:
> >public NullParameterException(String parameterName)
> >so that you can later find out which parameter was not passed.  It comes
> >in handy when you're checking for required form fields and the like.
> >
> >Hope this helps.
> >
> >-Rob
> >
> >On Tue, 13 Apr 1999, Jason Proctor wrote:
> >
> >> I'm seeing some weird behaviour with parameters that are passed to servlets
> >> as blank strings, ie in a URL such as
> >> http://machine/zone/servlet?param1=&param2=. These parameters end up having
> >> the value "null" (ie a 4-character string) rather than either a blank
> >> string or a null pointer, which is what I would expect.
> >>
> >> Here's the code -
> >>
> >> Enumeration parmNames = inRequest.getParameterNames();
> >>
> >> while ( parmNames.hasMoreElements() )
> >> {
> >>    String key = (String) parmNames.nextElement();
> >>
> >>    String value = inRequest.getParameter( key );
> >>
> >>    // value == "null" here
> >>    // in case where parameter is passed as ?name=&name=value
> >> }
> >>
> >> Any ideas anyone? Thanks in advance.
> >>
> >>
> >>
> >>
> >> ----------------------------------------------------------------------
> >> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> >> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
> >>
> 
> 
> 
> 
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
> 


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to