To check for both null and zero length:

String s = req.getParameter("value");
if (null == s || s.length() == 0) {
  // it's null or empty
}

For just null, use (null == s)

...Richard

-----Original Message-----
From: John McDonald [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 05, 2000 3:03 PM
To: [EMAIL PROTECTED]
Subject: [SERVLET-INTEREST] Checking for null


I am retrieving a value from a web page with req.getParameter("value"). How
do I check if the string is null without getting a null pointer exception.
Any ideas would be helpful.

___________________________________________________________________________
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