is a variable set?

Reply

Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

is a variable set?

 
0
  #1
Apr 27th, 2005
I am in the process of learning JSP and my question is how do I check to see if a variable exists? The equivalent of this in php would be
[php]if (isset($_POST['someVar']))[/php] or
[php]if (isset($_GET['someVar']))[/php]
any and all help would be appreciated!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: is a variable set?

 
0
  #2
Apr 27th, 2005
I'm pretty sure you can use defined in javascript. You can try:

  1. if (defined(somevariable)) {
  2. alert(somevariable);
  3. }

I'm not sure, but I think that's accurate.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: is a variable set?

 
0
  #3
Apr 28th, 2005
that wont work because i need it to be serverside, otherwise i might as well do it in html/javascript instead of jsp
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: is a variable set?

 
0
  #4
Apr 28th, 2005
You are talking about a regular variable right? Or are you talking about an evirionment variable?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: is a variable set?

 
0
  #5
Apr 28th, 2005
You mean a request or session attribute?
It's easy.

  1. <c:if test="${not empty someVar}">
  2. <%-- do what you need to do when the attribute is there --%>
  3. </c:if>

Actually if it's just to prevent errors when outputting something you don't need to check, JSTL is smart enough to ignore anything that's not there so
  1. <c:out value="${someVar}"/>
would just output nothing at all if someVar weren't there.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: is a variable set?

 
0
  #6
Apr 28th, 2005
i mean like a get (from url) or posted (client connection) variable
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: is a variable set?

 
0
  #7
Apr 28th, 2005
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6857 | Replies: 6
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC