DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JSP (http://www.daniweb.com/forums/forum24.html)
-   -   is a variable set? (http://www.daniweb.com/forums/thread22679.html)

paradox814 Apr 27th, 2005 3:58 pm
is a variable set?
 
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!

Comatose Apr 27th, 2005 6:12 pm
Re: is a variable set?
 
I'm pretty sure you can use defined in javascript. You can try:

if (defined(somevariable)) {
  alert(somevariable);
}

I'm not sure, but I think that's accurate.

paradox814 Apr 28th, 2005 2:45 am
Re: is a variable set?
 
that wont work because i need it to be serverside, otherwise i might as well do it in html/javascript instead of jsp

Comatose Apr 28th, 2005 7:29 am
Re: is a variable set?
 
You are talking about a regular variable right? Or are you talking about an evirionment variable?

jwenting Apr 28th, 2005 8:31 am
Re: is a variable set?
 
You mean a request or session attribute?
It's easy.

<c:if test="${not empty someVar}">
  <%-- do what you need to do when the attribute is there --%>
</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
<c:out value="${someVar}"/>
would just output nothing at all if someVar weren't there.

paradox814 Apr 28th, 2005 2:34 pm
Re: is a variable set?
 
i mean like a get (from url) or posted (client connection) variable

Comatose Apr 28th, 2005 2:42 pm
Re: is a variable set?
 
Hmn, will this help any: http://www.experts-exchange.com/Web/...21299007.html?


All times are GMT -4. The time now is 9:14 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC