Solved

Check if string/object null in query string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Pie chart in Jsp 20 206
SimpleDateFormat.parse examples 19 88
immutable object concept 5 111
Best practices to work on a spring MVC project 1 118
There is no doubt that cloud is gaining importance. Many of you must have read about this technology and its growing importance. More and more organisations are embracing this technology not forgetting start-ups. The process begins by dipping …
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

864 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

24 Experts available now in Live!

Get 1:1 Help Now