Solved

Java Loop all declared variables & their values

Posted on 2009-07-08
5
403 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 98
rhino JavaScript import, load 25 85
javap bin 2 36
tomcat not starting 6 45
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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.

803 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