?
Solved

Java Loop all declared variables & their values

Posted on 2009-07-08
5
Medium Priority
?
407 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 150 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 300 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 75 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 75 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 150 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

765 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