Solved

Java Loop all declared variables & their values

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 41
object oriented programming comparison 5 77
Java: anonymous class 4 29
java imports not found 4 17
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

789 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