Solved

Java Loop all declared variables & their values

Posted on 2009-07-08
5
397 Views
Last Modified: 2012-05-07
Hello,

I want to loop all local and global variables that are declared in a jsp.
How can i acces all these variables and print out their 'String' value ?

e.g
String var1 = "value1";
String var2 ="value2";
int var3 = 15;
int var4 = 16

output :
----------------------
var1   15
var2   value2
...
------------------
0
Comment
Question by:Xyleen
5 Comments
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 50 total points
ID: 24801377
you can't get the local( inside method ) variables but can do class/instance/member variables using reflection.
0
 
LVL 20

Accepted Solution

by:
a_b earned 100 total points
ID: 24801384
If you are trying to debug a jsp, in that case you should put the sysouts in spots where you want to see the variable values, otherwise like ksivananth says you will not be able to access the local variables, only  instance member will be visible - which  you can view via the toString() method if you have overridden that.
0
 
LVL 6

Assisted Solution

by:jwenting
jwenting earned 25 total points
ID: 24801536
You shouldn't have any Java code inside a JSP, so there should be nothing to "loop".

There's no way to "loop all variables" in Java anyway.
Or rather there is but it requires a lot of very tricky code and won't do what you want it to (nothing will).
0
 
LVL 13

Assisted Solution

by:Murali Murugesan
Murali Murugesan earned 25 total points
ID: 24810773
if you could tell us the reason why you are trying to iterate the local and global variables , we could suggest any alternatives.

-Murali*
0
 
LVL 5

Assisted Solution

by:Koma666
Koma666 earned 50 total points
ID: 24813005
Here is a description of how to use JDPA to debug variables:
http://forums.sun.com/thread.jspa?threadID=5278116
 Perhaps that helps.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now