Solved

Java Loop all declared variables & their values

Posted on 2009-07-08
5
406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

728 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