Solved

Check if string/object null in query string

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven webservice projet error 6 80
parse example 13 95
spring example errors 33 504
jsp error 6 47
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article discusses how to implement server side field validation and display customized error messages to the client.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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