Solved

Check if string/object null in query string

Posted on 2004-03-25
5
602 Views
Last Modified: 2010-04-01
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
Comment
Question by:894359
  • 4
5 Comments
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
unfortunately its also null.
0
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
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
 

Author Comment

by:894359
Comment Utility
I tried the null check and it fails for the second case!
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 250 total points
Comment Utility
hmm.. did you tried:
if( var1 != null && var1.length() > 0 )
0
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
or
if( !var1.equals("") )

it's the same as:

var1.length() > 0
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now