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
Solved

Check if string/object null in query string

Posted on 2004-03-25
5
606 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
ID: 10682929
unfortunately its also null.
0
 
LVL 14

Expert Comment

by:kennethxu
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 )
0
 

Author Comment

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

Accepted Solution

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

Expert Comment

by:kennethxu
ID: 10683044
or
if( !var1.equals("") )

it's the same as:

var1.length() > 0
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

Suggested Solutions

Title # Comments Views Activity
getting Http 404 error in jsp forms 8 81
dateFashion java challenge 9 146
excpetion with multiple catch 11 121
maven disable workspace resolution 1 21
If you are looking at this article, you have most likely been hit by some version of ransomware and are trying to find out if there is anything you can do, or what way you should react - READ ON!
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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