Is there a method like (!isDefined()) in JSP

A

anubhakhurana

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
 
M

Mark Space

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top