Check if string/object null in query string

If I'm passing a parameter in a query string:

test.jsp?var1=value1

and on the recieving page I get:

String var1 = request.getParameter("var1");

How do I check if no parameter was passed? For example if  this happens:

test.jsp

this checks
if (var1 != null) {}

but what about this case with no value in the query string???
test.jsp?var1=

I thought
 if (var1 != "") {}

 but that doesn't work, what's the check?



894359Asked:
Who is Participating?
 
kennethxuConnect With a Mentor Commented:
hmm.. did you tried:
if( var1 != null && var1.length() > 0 )
0
 
kennethxuCommented:
unfortunately its also null.
0
 
kennethxuCommented:
in your application, you shoudl thread test.jsp?var1= the same as test.jsp
I always do this check:
if( var1 != null && var1.length() > 0 )
0
 
894359Author Commented:
I tried the null check and it fails for the second case!
0
 
kennethxuCommented:
or
if( !var1.equals("") )

it's the same as:

var1.length() > 0
0
All Courses

From novice to tech pro — start learning today.