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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top