[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Check if string/object null in query string

Posted on 2004-03-25
Medium Priority
Last Modified: 2010-04-01
If I'm passing a parameter in a query string:


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:


this checks
if (var1 != null) {}

but what about this case with no value in the query string???

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

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

Question by:894359
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
LVL 14

Expert Comment

ID: 10682929
unfortunately its also null.
LVL 14

Expert Comment

ID: 10682944
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 )

Author Comment

ID: 10683004
I tried the null check and it fails for the second case!
LVL 14

Accepted Solution

kennethxu earned 1000 total points
ID: 10683037
hmm.. did you tried:
if( var1 != null && var1.length() > 0 )
LVL 14

Expert Comment

ID: 10683044
if( !var1.equals("") )

it's the same as:

var1.length() > 0

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

656 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