Hello! I have 2 files A.jsp and B.jsp. A.jsp is including B.jsp. There
is a variable defined in A.jsp which is being used in B.jsp. Now B.jsp
should check that if the variable is not defined than it should define
and put a default value in the variable in B.jsp. So in JSP do we have
something like !isdefined(var). or is there any other way I can solve
this problem.
Thanks in Advance
Anubha
> Hello! I have 2 files A.jsp and B.jsp. A.jsp is including B.jsp. There
> is a variable defined in A.jsp which is being used in B.jsp. Now B.jsp
> should check that if the variable is not defined than it should define
> and put a default value in the variable in B.jsp. So in JSP do we have
> something like !isdefined(var). or is there any other way I can solve
> this problem.
I'm pretty sure what your asking is not directly possible. Java, unlike
scripting languages like Perl, JavaScript and others, does not permit
you to access undefined variables at all. It's an error at compile time.
If you are having problems like this, you probably want to pass a
(defined) object like a collection, then you can check the contents of
the collection for what pairs of data are defined. This can get
complicated if you over use it, so be careful.
Also, there's a process called Reflection that does allow you to
discover the type, methods, and other information about objects, without
knowing anything about them to begin with. This might be useful,
depending on what you are trying to do.
But if "var" isn't defined, then your program won't compile, and you
can't test for it, because it would have to be defined first.
anubhakhurana@gmail.com - 12 Oct 2006 07:53 GMT
Thanks a lot for your reply. It was really helpful.
> > Hello! I have 2 files A.jsp and B.jsp. A.jsp is including B.jsp. There
> > is a variable defined in A.jsp which is being used in B.jsp. Now B.jsp
[quoted text clipped - 19 lines]
> But if "var" isn't defined, then your program won't compile, and you
> can't test for it, because it would have to be defined first.