Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 620
  • Last Modified:

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?



0
894359
Asked:
894359
  • 4
1 Solution
 
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:
hmm.. did you tried:
if( var1 != null && var1.length() > 0 )
0
 
kennethxuCommented:
or
if( !var1.equals("") )

it's the same as:

var1.length() > 0
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now