Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

see if varible is declared

Status
Not open for further replies.

joelmac

Programmer
Jun 4, 2002
92
CA
Hi there,

Is there a way that I can see if a varible is declared?

I'm including Headers on my pages using <%@include file="Header.jsp"%>. Some pages will declare varibles for the Header to read, but if no varible is declared I want the Header to just ignore it. How would I do this?

Thanks,

________________________
JoelMac
 
perhaps store your variables in a HashMap, and see if the key for your variable exists? like
Code:
HashMap vars = new HashMap();

if (vars.containsKey("someKey")) {
  //  var exists
}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
That's a good idea, but I still have to declare something. I want most of my pages to behave in a 'default' manner and only declare and pass the varible for special cases.

________________________
JoelMac
 
hmmm, that's what I thought, Thanks anyway.

________________________
JoelMac
 
I've found a solution to my problem. I've declared my HashMap in the Header like this:

Code:
<%!  //  <--- NOTE: the "!"
     HashMap props = new HashMap();
%>

This way I can refer to the props variable in files that include the Header before the line where the Header is included.

________________________
JoelMac
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top