• Post Reply Bookmark Topic Watch Topic
  • New Topic

if else and nulls  RSS feed

 
g forte
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should be a simple one but I cant get it to work:
Basically I have a jsp that passes querystring values CID and altCID. I need to do an if/else statement to determine what value to asign the variable strCID.This is what I have done:
String strCID = null;
String cid = request.getParameter("CID");
String altcid = request.getParameter("altCID");
if(cid == "")
{strCID=altcid;}
else {strCID = cid;}
I also tried if(cid == null)
Neither of these work properly. If request.getParameter("CID") has a value the assignment works. If request.getParameter("CID") doesnt have a value strCID doesnt get assigned a value.
TIA!
 
Nagendra Prasad
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String values can be checked as thus:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!