Check if string/object null in query string

Posted on 2004-03-25
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 250 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

695 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